CTT/Server/Hotfix/Game/Common/Bag/AddPetGoodsEffect.cs

65 lines
1.9 KiB
C#
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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--;
UnitHelper.SaveComponenet(data);
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;
}
}
}