316 lines
7.5 KiB
C#
316 lines
7.5 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-12-01
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "GameLevel" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 游戏状态管理
|
|||
|
/// </summary>
|
|||
|
partial class GameLevel
|
|||
|
{
|
|||
|
public class BuffInfo
|
|||
|
{
|
|||
|
public int id;
|
|||
|
public int value;
|
|||
|
}
|
|||
|
|
|||
|
public readonly Dictionary<string, BuffInfo> buffInfoDict = new Dictionary<string, BuffInfo>();
|
|||
|
|
|||
|
public readonly BattleResult battleResult = new BattleResult();
|
|||
|
|
|||
|
public void InitBattleResult()
|
|||
|
{
|
|||
|
battleResult.applyStep = 0;
|
|||
|
|
|||
|
battleResult.levelId = curLevelId;
|
|||
|
battleResult.stageIndex = curStageIndex;
|
|||
|
battleResult.stageIndexMax = maxStageIndex;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void UpdateBattleResult()
|
|||
|
{
|
|||
|
battleResult.stageIndex = curStageIndex;
|
|||
|
battleResult.playerHpPercent = (int)(EntityMainPlayer.Instance.hpRatio * 100f);
|
|||
|
battleResult.duration = (int)(Time.unscaledTime - _startLevelTime);
|
|||
|
KStatistics.Instance.ReportEvent_Battle("普通", curChapterId, curLevelId, curStageIndex, 0, 3, battleResult.playerDeath, "", battleResult.duration, battleResult.duration, battleResult.playerHpPercent);
|
|||
|
}
|
|||
|
|
|||
|
public void SetLevelResult(bool success, int duration, string reason)
|
|||
|
{
|
|||
|
battleResult.applyStep = 0;
|
|||
|
battleResult.duration = duration;
|
|||
|
battleResult.reason = reason;
|
|||
|
|
|||
|
battleResult.success = success;
|
|||
|
battleResult.levelId = curLevelId;
|
|||
|
battleResult.stageIndex = curStageIndex;
|
|||
|
battleResult.stageIndexMax = maxStageIndex;
|
|||
|
//battleResult.exp = curLevelItem.exp / (success ? 1 : 2);
|
|||
|
|
|||
|
if (success)
|
|||
|
{
|
|||
|
AddDifficult();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
ReduceDifficult();
|
|||
|
}
|
|||
|
|
|||
|
RemoveNormalLevelState();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="itemId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public EntityItemEquipment CollectEquipment(int itemId)
|
|||
|
{
|
|||
|
var equipment = BagProxy.Instance.NewEquipment(itemId);
|
|||
|
if (equipment != null)
|
|||
|
battleResult.equipments.Add(equipment);
|
|||
|
return equipment;
|
|||
|
}
|
|||
|
|
|||
|
public void CollecMoney(int id, int amount)
|
|||
|
{
|
|||
|
if (amount < 9999)
|
|||
|
{
|
|||
|
battleResult.AddMoney(id, amount);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void CollecProp(int id, int amount)
|
|||
|
{
|
|||
|
if (amount < 99)
|
|||
|
{
|
|||
|
battleResult.AddProp(id, amount);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 宝石
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <param name="amount"></param>
|
|||
|
public void CollecGem(int id, int amount)
|
|||
|
{
|
|||
|
if (amount < 99)
|
|||
|
{
|
|||
|
battleResult.AddProp(id, amount);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void CollectExp(int amount)
|
|||
|
{
|
|||
|
if (amount < 1000)
|
|||
|
battleResult.exp += amount;
|
|||
|
}
|
|||
|
|
|||
|
public void OnBossKill(int amount)
|
|||
|
{
|
|||
|
if (amount < 10)
|
|||
|
battleResult.bossKilled += amount;
|
|||
|
}
|
|||
|
|
|||
|
public void OnMinionKill(int amount)
|
|||
|
{
|
|||
|
if (amount < 100)
|
|||
|
battleResult.minionKilled += amount;
|
|||
|
}
|
|||
|
|
|||
|
public void OnSkill(int skillId)
|
|||
|
{
|
|||
|
battleResult.CastSkill(skillId);
|
|||
|
}
|
|||
|
|
|||
|
public void OnPlayerDead()
|
|||
|
{
|
|||
|
ReduceDifficult();
|
|||
|
battleResult.playerDeath += 1;
|
|||
|
}
|
|||
|
|
|||
|
public void AddBuff(string name, int value)
|
|||
|
{
|
|||
|
int attributeId = 0;
|
|||
|
switch (name)
|
|||
|
{
|
|||
|
case "red":
|
|||
|
attributeId = (int)CombatAttributeId.Attack;
|
|||
|
EntityMainPlayer.Instance.AttributeUp(attributeId, 0, GlobalVar.BuffAddition);
|
|||
|
break;
|
|||
|
case "yellow":
|
|||
|
attributeId = (int)CombatAttributeId.Defence;
|
|||
|
EntityMainPlayer.Instance.AttributeUp(attributeId, 0, GlobalVar.BuffAddition);
|
|||
|
break;
|
|||
|
case "blue":
|
|||
|
attributeId = (int)CombatAttributeId.Hp;
|
|||
|
EntityMainPlayer.Instance.AttributeUp(attributeId, 0, GlobalVar.BuffAddition);
|
|||
|
break;
|
|||
|
case "green":
|
|||
|
EntityMainPlayer.Instance.HpUp(0, 10);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (buffInfoDict.TryGetValue(name, out var buffInfo))
|
|||
|
{
|
|||
|
buffInfo.value += value;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
buffInfoDict.Add(name, new BuffInfo
|
|||
|
{
|
|||
|
id = attributeId,
|
|||
|
value = value,
|
|||
|
});
|
|||
|
}
|
|||
|
GlobalNotifier.PostNotification(GlobalDefine.EVENT_SHOW_BUFF);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void SaveNormalLevelState()
|
|||
|
{
|
|||
|
var dataList = F.ListPool<int>.Get();
|
|||
|
|
|||
|
var skills = MovesShop.Instance.studiedMoves;
|
|||
|
dataList.Add(skills.Count);
|
|||
|
dataList.AddRange(skills);
|
|||
|
|
|||
|
dataList.Add(buffInfoDict.Count);
|
|||
|
foreach (var item in buffInfoDict.Values)
|
|||
|
{
|
|||
|
dataList.Add(item.id);
|
|||
|
dataList.Add(item.value);
|
|||
|
}
|
|||
|
|
|||
|
var equipments = battleResult.equipments;
|
|||
|
dataList.Add(equipments.Count);
|
|||
|
for (int i = 0; i < equipments.Count; i++)
|
|||
|
{
|
|||
|
dataList.Add(equipments[i].id);
|
|||
|
}
|
|||
|
|
|||
|
var moneys = battleResult.moneyDict;
|
|||
|
dataList.Add(moneys.Count);
|
|||
|
foreach (var money in moneys)
|
|||
|
{
|
|||
|
dataList.Add(money.Key);
|
|||
|
dataList.Add(money.Value);
|
|||
|
}
|
|||
|
|
|||
|
var props = battleResult.propDict;
|
|||
|
dataList.Add(props.Count);
|
|||
|
foreach (var prop in props)
|
|||
|
{
|
|||
|
dataList.Add(prop.Key);
|
|||
|
dataList.Add(prop.Value);
|
|||
|
}
|
|||
|
|
|||
|
dataList.Add(EntityMainPlayer.Instance.curHp);
|
|||
|
dataList.Add(EntityMainPlayer.Instance.deathCount);
|
|||
|
|
|||
|
LevelProxy.Instance.SavePlayingLevelState(curLevelId, curStageIndex + 1, dataList);
|
|||
|
F.ListPool<int>.Release(dataList);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void RemoveNormalLevelState()
|
|||
|
{
|
|||
|
LevelProxy.Instance.RemovePlayingLevelState();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void LoadNormalLevelState()
|
|||
|
{
|
|||
|
if (GlobalVar.SavePlayingStateData.Count > 0)
|
|||
|
{
|
|||
|
int index = 0;
|
|||
|
var skillCount = GlobalVar.SavePlayingStateData[index++];
|
|||
|
var skills = new List<int>(skillCount);
|
|||
|
for (int i = 0; i < skillCount; i++)
|
|||
|
{
|
|||
|
int id = GlobalVar.SavePlayingStateData[index++];
|
|||
|
skills.Add(id);
|
|||
|
}
|
|||
|
MovesShop.Instance.StudyMoves(skills);
|
|||
|
|
|||
|
int buffCount = GlobalVar.SavePlayingStateData[index++];
|
|||
|
for (int i = 0; i < buffCount; i++)
|
|||
|
{
|
|||
|
int id = GlobalVar.SavePlayingStateData[index++];
|
|||
|
int count = GlobalVar.SavePlayingStateData[index++];
|
|||
|
}
|
|||
|
|
|||
|
int equipmentCount = GlobalVar.SavePlayingStateData[index++];
|
|||
|
for (int i = 0; i < equipmentCount; i++)
|
|||
|
{
|
|||
|
int id = GlobalVar.SavePlayingStateData[index++];
|
|||
|
var equipment = ItemProxy.Instance.GetEquipment(id);
|
|||
|
if (equipment != null)
|
|||
|
battleResult.equipments.Add(equipment);
|
|||
|
}
|
|||
|
|
|||
|
int moneyCount = GlobalVar.SavePlayingStateData[index++];
|
|||
|
for (int i = 0; i < moneyCount; i++)
|
|||
|
{
|
|||
|
int id = GlobalVar.SavePlayingStateData[index++];
|
|||
|
int count = GlobalVar.SavePlayingStateData[index++];
|
|||
|
battleResult.AddMoney(id, count);
|
|||
|
}
|
|||
|
|
|||
|
int propCount = GlobalVar.SavePlayingStateData[index++];
|
|||
|
for (int i = 0; i < propCount; i++)
|
|||
|
{
|
|||
|
int id = GlobalVar.SavePlayingStateData[index++];
|
|||
|
int count = GlobalVar.SavePlayingStateData[index++];
|
|||
|
battleResult.AddProp(id, count);
|
|||
|
}
|
|||
|
|
|||
|
if (index < GlobalVar.SavePlayingStateData.Count)
|
|||
|
{
|
|||
|
EntityMainPlayer.Instance.curHp = GlobalVar.SavePlayingStateData[index++];
|
|||
|
EntityMainPlayer.Instance.deathCount = GlobalVar.SavePlayingStateData[index++];
|
|||
|
}
|
|||
|
|
|||
|
GlobalVar.SavePlayingStateData.Clear();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void SaveEndlessLevelState()
|
|||
|
{
|
|||
|
LevelProxy.Instance.CompleteEndlessLevel(curStageIndex);
|
|||
|
}
|
|||
|
|
|||
|
public void SaveClimbLevelState()
|
|||
|
{
|
|||
|
LevelProxy.Instance.CompleteClimbLevel(curStageIndex);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|