2021-04-08 20:09:59 +08:00
|
|
|
|
using Cal;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public class PetAwakeSystem : AwakeSystem<Pet>
|
|
|
|
|
{
|
|
|
|
|
public override void Awake(Pet self)
|
|
|
|
|
{
|
|
|
|
|
self.level = 1;
|
|
|
|
|
self.name = "宠物";
|
|
|
|
|
self.Load();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class PetLoadSystem : LoadSystem<Pet>
|
|
|
|
|
{
|
|
|
|
|
public override void Load(Pet self)
|
|
|
|
|
{
|
|
|
|
|
self.Load();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class PetDeserializeSystem : DeserializeSystem<Pet>
|
|
|
|
|
{
|
|
|
|
|
public override void Deserialize(Pet self)
|
|
|
|
|
{
|
|
|
|
|
self.Load();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-09 00:48:56 +08:00
|
|
|
|
public class PetDestroySystem : DestroySystem<Pet>
|
|
|
|
|
{
|
|
|
|
|
public override void Destroy(Pet self)
|
|
|
|
|
{
|
|
|
|
|
self.petId = 0;
|
|
|
|
|
self.exp = 0;
|
|
|
|
|
self.intimacy = 0;
|
|
|
|
|
self.addToCharacter.Clear();
|
|
|
|
|
self.getAttributeFunc = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-08 20:09:59 +08:00
|
|
|
|
public static class PetSystem
|
|
|
|
|
{
|
|
|
|
|
public static void Load(this Pet self)
|
|
|
|
|
{
|
|
|
|
|
self.getAttributeFunc += self.GetAttribute;
|
|
|
|
|
self.Init();
|
|
|
|
|
}
|
|
|
|
|
public static void Init(this Pet self)
|
|
|
|
|
{
|
|
|
|
|
int key = (int)AttributeType.力量;
|
|
|
|
|
if (!self.addToCharacter.ContainsKey(key))
|
|
|
|
|
self.addToCharacter[key] = 0;
|
|
|
|
|
key = (int)AttributeType.敏捷;
|
|
|
|
|
if (!self.addToCharacter.ContainsKey(key))
|
|
|
|
|
self.addToCharacter[key] = 0;
|
|
|
|
|
key = (int)AttributeType.精神;
|
|
|
|
|
if (!self.addToCharacter.ContainsKey(key))
|
|
|
|
|
self.addToCharacter[key] = 0;
|
|
|
|
|
key = (int)AttributeType.智慧;
|
|
|
|
|
if (!self.addToCharacter.ContainsKey(key))
|
|
|
|
|
self.addToCharacter[key] = 0;
|
|
|
|
|
key = (int)AttributeType.体质;
|
|
|
|
|
if (!self.addToCharacter.ContainsKey(key))
|
|
|
|
|
self.addToCharacter[key] = 0;
|
|
|
|
|
key = (int)AttributeType.耐力;
|
|
|
|
|
if (!self.addToCharacter.ContainsKey(key))
|
|
|
|
|
self.addToCharacter[key] = 0;
|
|
|
|
|
}
|
|
|
|
|
public static float GetAttribute(this Pet self,AttributeType attributeType)
|
|
|
|
|
{
|
|
|
|
|
float bound = 0f;
|
|
|
|
|
foreach (var kv in self.addToCharacter)
|
|
|
|
|
{
|
|
|
|
|
if ((int)attributeType == kv.Key)
|
|
|
|
|
bound += kv.Value;
|
|
|
|
|
}
|
|
|
|
|
return bound;
|
|
|
|
|
}
|
|
|
|
|
public static string AddLevel(this Pet self,int level)
|
|
|
|
|
{
|
|
|
|
|
self.level+=level;
|
|
|
|
|
using var listComponent = ListComponent<int>.Create();
|
|
|
|
|
listComponent.List.AddRange(self.addToCharacter.Keys);
|
|
|
|
|
foreach (var key in listComponent.List)
|
|
|
|
|
{
|
|
|
|
|
self.addToCharacter[key] += 10*level;
|
|
|
|
|
}
|
|
|
|
|
Log.Info($"宠物升级啦! level:{self.level} exp:{self.exp}");
|
|
|
|
|
CharacterHelper.SyncNumeric(self.GetParent<Unit>());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
public static string AddExp(this Pet self,int exp)
|
|
|
|
|
{
|
|
|
|
|
exp += self.exp;
|
|
|
|
|
int addLevel = 0;
|
|
|
|
|
while (exp > 100+self.level*10)
|
|
|
|
|
{
|
|
|
|
|
exp -= 100 + self.level * 10;
|
|
|
|
|
addLevel++;
|
|
|
|
|
}
|
|
|
|
|
self.exp = Math.Clamp(exp, 0, int.MaxValue);
|
|
|
|
|
self.AddLevel(addLevel);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
public static string ChangeName(this Pet self, string name)
|
|
|
|
|
{
|
|
|
|
|
name = name.TrimEnd().Trim(new char[]{'\n','狗','夏'});
|
|
|
|
|
if (name.Length > 7)
|
|
|
|
|
{
|
|
|
|
|
return "长度最大为7";
|
|
|
|
|
}
|
|
|
|
|
self.name = name;
|
|
|
|
|
Log.Info($"宠物改名:{self.name}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|