|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
{
|
|
|
|
[FriendClass(typeof (Unit))]
|
|
|
|
public static class CheatHelper
|
|
|
|
{
|
|
|
|
public static async ETTask<int> AddItem(Unit unit, int id, int type, uint num)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
C2M_Cheat msg = new C2M_Cheat() { Type = type, Id = id, Num = num };
|
|
|
|
M2C_Cheat resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_Cheat;
|
|
|
|
if (resp.Error == ErrorCode.ERR_Success)
|
|
|
|
{
|
|
|
|
if (type == 1)
|
|
|
|
{
|
|
|
|
StoreComponent storeComponent = unit.GetComponent<StoreComponent>();
|
|
|
|
if (num >= 0)
|
|
|
|
{
|
|
|
|
storeComponent.Add(id, num);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
storeComponent.Remove(id, (int) Math.Abs(num));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == 2)
|
|
|
|
{
|
|
|
|
if (id == NumericType.Water)
|
|
|
|
{
|
|
|
|
unit.Water += num;
|
|
|
|
}
|
|
|
|
else if (id == NumericType.Food)
|
|
|
|
{
|
|
|
|
unit.Food += num;
|
|
|
|
}
|
|
|
|
else if (id == NumericType.SilverTael)
|
|
|
|
{
|
|
|
|
if (num >= 0)
|
|
|
|
{
|
|
|
|
unit.SilverTael += (int) Math.Abs(num);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unit.SilverTael -= (int) Math.Abs(num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (id == NumericType.GoldIngot)
|
|
|
|
{
|
|
|
|
if (num >= 0)
|
|
|
|
{
|
|
|
|
unit.GoldIngot += (int) Math.Abs(num);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unit.GoldIngot -= (int) Math.Abs(num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (id == NumericType.Season)
|
|
|
|
{
|
|
|
|
if (num >= 0)
|
|
|
|
{
|
|
|
|
unit.Season += (int) Math.Abs(num);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unit.Season -= (int) Math.Abs(num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (id == NumericType.Scale)
|
|
|
|
{
|
|
|
|
if (num >= 0)
|
|
|
|
{
|
|
|
|
unit.Scale += (int) Math.Abs(num);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unit.Scale -= (int) Math.Abs(num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (id == NumericType.Prosperity)
|
|
|
|
{
|
|
|
|
if (num >= 0)
|
|
|
|
{
|
|
|
|
unit.Prosperity += (int) Math.Abs(num);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unit.Prosperity -= (int) Math.Abs(num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (id == NumericType.Time)
|
|
|
|
{
|
|
|
|
unit.GameTime = (int) num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log.Error(resp.Error.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.Error;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Log.Error(e.ToString());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async ETTask<int> AddItemList(Unit unit, List<int> configIds, List<int> nums)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
C2M_CheatItemList msg = new C2M_CheatItemList() { ConfigIds = configIds, Nums = nums };
|
|
|
|
M2C_CheatItemList resp = await unit.ZoneScene().GetComponent<SessionComponent>().Session.Call(msg) as M2C_CheatItemList;
|
|
|
|
if (resp.Error == ErrorCode.ERR_Success)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < configIds.Count; i++)
|
|
|
|
{
|
|
|
|
unit.GetComponent<StoreComponent>().Add(configIds[i], nums[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resp.Error;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Log.Error(e.ToString());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|