2021-04-08 20:09:59 +08:00
|
|
|
|
using Cal;
|
2021-04-10 19:49:32 +08:00
|
|
|
|
using Cal.DataTable;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public class PetAwakeSystem : AwakeSystem<Pet>
|
|
|
|
|
{
|
2021-04-10 19:49:32 +08:00
|
|
|
|
public override void Awake(Pet self)
|
|
|
|
|
{
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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-10 19:49:32 +08:00
|
|
|
|
public class PetChangeSystem : ChangeSystem<Pet>
|
|
|
|
|
{
|
|
|
|
|
public override void Change(Pet self)
|
|
|
|
|
{
|
2021-04-12 23:38:54 +08:00
|
|
|
|
UnitHelper.SaveComponenet(self).Coroutine();
|
2021-04-11 19:50:39 +08:00
|
|
|
|
Unit unit = self.GetParent<Unit>();
|
2021-04-10 19:49:32 +08:00
|
|
|
|
M2C_SyncPet proto = new()
|
|
|
|
|
{
|
|
|
|
|
UnitId=self.Id,
|
|
|
|
|
petId=self.petId,
|
|
|
|
|
exp=self.exp,
|
|
|
|
|
isShow=self.isShow,
|
|
|
|
|
level=self.level,
|
|
|
|
|
name=self.name,
|
|
|
|
|
intimacy=self.intimacy
|
|
|
|
|
};
|
|
|
|
|
BrocastComponent brocastComponent = unit.GetComponent<BrocastComponent>();
|
|
|
|
|
brocastComponent?.Brocast(proto);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-09 00:48:56 +08:00
|
|
|
|
public class PetDestroySystem : DestroySystem<Pet>
|
|
|
|
|
{
|
2021-04-10 19:49:32 +08:00
|
|
|
|
public override void Destroy(Pet self)
|
2021-04-09 00:48:56 +08:00
|
|
|
|
{
|
|
|
|
|
self.petId = 0;
|
|
|
|
|
self.exp = 0;
|
|
|
|
|
self.intimacy = 0;
|
2021-04-10 19:49:32 +08:00
|
|
|
|
self.isShow = false;
|
2021-04-09 00:48:56 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
2021-04-12 23:38:54 +08:00
|
|
|
|
|
|
|
|
|
private static void Init(this Pet self)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
2021-04-12 23:38:54 +08:00
|
|
|
|
|
|
|
|
|
private static float GetAttribute(this Pet self, AttributeType attributeType)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
float bound = 0f;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (KeyValuePair<int, float> kv in self.addToCharacter)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
if ((int)attributeType == kv.Key)
|
|
|
|
|
bound += kv.Value;
|
|
|
|
|
}
|
|
|
|
|
return bound;
|
|
|
|
|
}
|
2021-04-12 23:38:54 +08:00
|
|
|
|
|
|
|
|
|
private static string AddLevel(this Pet self, int level)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-10 19:49:32 +08:00
|
|
|
|
self.level += level;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
using ListComponent<int> listComponent = ListComponent<int>.Create();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
listComponent.List.AddRange(self.addToCharacter.Keys);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (int key in listComponent.List)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-10 19:49:32 +08:00
|
|
|
|
self.addToCharacter[key] += 10 * level;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
Log.Info($"宠物升级啦! level:{self.level} exp:{self.exp}");
|
|
|
|
|
CharacterHelper.SyncNumeric(self.GetParent<Unit>());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-04-10 19:49:32 +08:00
|
|
|
|
public static string AddExp(this Pet self, int exp)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
exp += self.exp;
|
|
|
|
|
int addLevel = 0;
|
2021-04-10 19:49:32 +08:00
|
|
|
|
int stage = GetStage(self.level);
|
|
|
|
|
|
|
|
|
|
while (exp > GetNeedExp(stage, self.level))
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-10 19:49:32 +08:00
|
|
|
|
stage = GetStage(self.level + addLevel);
|
|
|
|
|
exp -= GetNeedExp(stage, self.level);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
addLevel++;
|
|
|
|
|
}
|
|
|
|
|
self.exp = Math.Clamp(exp, 0, int.MaxValue);
|
|
|
|
|
self.AddLevel(addLevel);
|
2021-04-10 19:49:32 +08:00
|
|
|
|
Game.EventSystem.Change(self);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-04-10 19:49:32 +08:00
|
|
|
|
private static int GetNeedExp(int stage, int level)
|
|
|
|
|
{
|
|
|
|
|
PetLevelConfig petLevelConfig = PetLevelConfigCategory.Instance.Get(stage);
|
|
|
|
|
return petLevelConfig.Exp + petLevelConfig.ExpByLevel * level;
|
|
|
|
|
}
|
|
|
|
|
private static int GetStage(int level)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
int[] arr = new int[] { 0, 50, 100, 200, 500, 1000 };
|
2021-04-10 19:49:32 +08:00
|
|
|
|
for (int i = 0; i < arr.Length; i++)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
int item = arr[i];
|
2021-04-10 19:49:32 +08:00
|
|
|
|
if (level <= item)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return arr.Length - 1;
|
|
|
|
|
}
|
2021-04-12 23:38:54 +08:00
|
|
|
|
public static void AddIntimacy(this Pet self,int intimacy)
|
|
|
|
|
{
|
|
|
|
|
self.intimacy += intimacy;
|
|
|
|
|
Game.EventSystem.Change(self);
|
|
|
|
|
}
|
2021-04-08 20:09:59 +08:00
|
|
|
|
public static string ChangeName(this Pet self, string name)
|
|
|
|
|
{
|
2021-04-10 19:49:32 +08:00
|
|
|
|
|
|
|
|
|
if (!FilterCharHelper.IsInvalid(name))
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-10 19:49:32 +08:00
|
|
|
|
return "昵称不能超过7位,不能含有特殊字符";
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
self.name = name;
|
|
|
|
|
Log.Info($"宠物改名:{self.name}");
|
2021-04-10 19:49:32 +08:00
|
|
|
|
Game.EventSystem.Change(self);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|