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(); if (data.petEatCount <= 0) { return "喂养次数达到上限"; } Pet pet = this.unit.GetComponent(); 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; } } }