zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/Common/Bag/AddPetGoodsEffect.cs

65 lines
1.9 KiB
C#
Raw Normal View History

2021-04-15 00:12:07 +08:00
using System;
using Cal.DataTable;
namespace ET
{
public class AddPetGoodsEffect: GoodsEffect
{
public override string Init(Unit _unit, GoodsBase goodsBase, bool isLock = false)
{
base.unit = _unit;
GoodsBase = goodsBase;
return Run();
}
private string Run()
{
PlayerData data = this.unit.GetComponent<PlayerData>();
if (data.petEatCount <= 0)
{
return "喂养次数达到上限";
}
Pet pet = this.unit.GetComponent<Pet>();
if (pet.petState is not (Pet.PetState.Idle or Pet.PetState.Follow))
{
return "行动中不能喂养";
}
var addKVArr= this.GoodsBase.OtherParam.Split('_');
if (addKVArr.Length <= 0)
return "系统错误请提交bug";
data.petEatCount--;
2021-06-29 11:28:15 +08:00
UnitHelper.SaveComponenet(data);
2021-04-15 00:12:07 +08:00
foreach (string kvString in addKVArr)
{
try
{
var kv = kvString.Split(':');
switch (kv[0])
{
case "exp":
pet.AddExp(int.Parse(kv[1]));
break;
case "active":
pet.AddActive(int.Parse(kv[1]));
break;
case "intimacy":
pet.AddIntimacy(int.Parse(kv[1]));
break;
}
}
catch (Exception e)
{
Log.Error(e);
}
}
return string.Empty;
}
public override async ETVoid Execute()
{
await ETTask.CompletedTask;
}
}
}