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;
|
2021-04-15 00:12:07 +08:00
|
|
|
|
using System.Linq;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
public class PetAwakeSystem: AwakeSystem<Pet>
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
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 = "宠物";
|
2021-04-15 00:12:07 +08:00
|
|
|
|
self.actionEndTime = 0;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
self.Load();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
|
|
|
|
public class PetLoadSystem: LoadSystem<Pet>
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
public override void Load(Pet self)
|
|
|
|
|
{
|
|
|
|
|
self.Load();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
|
|
|
|
public class PetDeserializeSystem: DeserializeSystem<Pet>
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
public override void Deserialize(Pet self)
|
|
|
|
|
{
|
|
|
|
|
self.Load();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
|
|
|
|
public class PetChangeSystem: ChangeSystem<Pet>
|
2021-04-10 19:49:32 +08:00
|
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
UnitId = self.Id,
|
|
|
|
|
petId = self.petId,
|
|
|
|
|
exp = self.exp,
|
|
|
|
|
isShow = self.isShow,
|
|
|
|
|
level = self.level,
|
|
|
|
|
name = self.name,
|
|
|
|
|
intimacy = self.intimacy,
|
2021-04-10 19:49:32 +08:00
|
|
|
|
};
|
|
|
|
|
BrocastComponent brocastComponent = unit.GetComponent<BrocastComponent>();
|
|
|
|
|
brocastComponent?.Brocast(proto);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
|
|
|
|
public class PetDestroySystem: DestroySystem<Pet>
|
2021-04-09 00:48:56 +08:00
|
|
|
|
{
|
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-15 00:12:07 +08:00
|
|
|
|
self.actionEndTime = 0;
|
2021-04-10 19:49:32 +08:00
|
|
|
|
self.isShow = false;
|
2021-04-15 00:12:07 +08:00
|
|
|
|
self.petState = Pet.PetState.Idle;
|
2021-04-09 00:48:56 +08:00
|
|
|
|
self.addToCharacter.Clear();
|
|
|
|
|
self.getAttributeFunc = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
}
|
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
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
if ((int) attributeType == kv.Key)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
bound += kv.Value;
|
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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-15 00:12:07 +08:00
|
|
|
|
PetConfig petConfig = PetConfigCategory.Instance.Get(self.petId);
|
|
|
|
|
foreach (PetConfig.AddAttibuteMap addAttibuteMap in petConfig.AddAttibuteMapArr)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
if (!self.addToCharacter.TryGetValue(addAttibuteMap.Key, out float old))
|
|
|
|
|
self.addToCharacter[addAttibuteMap.Key] = 0;
|
|
|
|
|
self.addToCharacter[addAttibuteMap.Key] = old + addAttibuteMap.Value * level;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
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-15 00:12:07 +08:00
|
|
|
|
|
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
|
|
|
|
|
2021-04-15 00:12:07 +08:00
|
|
|
|
while (exp > GetNeedExp(self.petId, self.level))
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
exp -= GetNeedExp(self.petId, self.level);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
addLevel++;
|
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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-15 00:12:07 +08:00
|
|
|
|
|
|
|
|
|
private static int GetNeedExp(int petId, int level)
|
2021-04-10 19:49:32 +08:00
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
PetLevelConfig petLevelConfig = PetLevelConfigCategory.Instance.Get(petId);
|
2021-04-10 19:49:32 +08:00
|
|
|
|
return petLevelConfig.Exp + petLevelConfig.ExpByLevel * level;
|
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
|
|
|
|
public static void AddIntimacy(this Pet self, int intimacy)
|
2021-04-12 23:38:54 +08:00
|
|
|
|
{
|
|
|
|
|
self.intimacy += intimacy;
|
|
|
|
|
Game.EventSystem.Change(self);
|
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
|
|
|
|
public static void AddActive(this Pet self, int active)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
2021-04-15 00:12:07 +08:00
|
|
|
|
PlayerData data = self.Parent.GetComponent<PlayerData>();
|
|
|
|
|
data.petActive += active;
|
|
|
|
|
}
|
2021-04-10 19:49:32 +08:00
|
|
|
|
|
2021-04-15 00:12:07 +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
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 探险
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="self"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string Explore(this Pet self)
|
|
|
|
|
{
|
|
|
|
|
if (self.petState is not (Pet.PetState.Idle))
|
|
|
|
|
{
|
|
|
|
|
return "行动中";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerData data = self.Parent.GetComponent<PlayerData>();
|
|
|
|
|
if (data.petActive <= 0) return "活跃度不足";
|
|
|
|
|
|
|
|
|
|
const int index = (int) PetExploreConfigCategory.PetActionType.Explore;
|
|
|
|
|
var configList = PetExploreConfigCategory.Instance.GetListByType((PetExploreConfigCategory.PetActionType) index);
|
|
|
|
|
int petActionIndexFlag = IntFlagHelper.GetFlag(data.petActionIndexFlag, index - 1, 2);
|
|
|
|
|
if (petActionIndexFlag >= configList.Count)
|
|
|
|
|
return "次数达到上限";
|
|
|
|
|
PetExploreConfig config = configList[petActionIndexFlag];
|
|
|
|
|
self.actionEndTime = Game.TimeInfo.ClientNow() + config.Time;
|
|
|
|
|
data.petActive--;
|
|
|
|
|
self.petState = Pet.PetState.Explore;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 嬉戏
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="self"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string Play(this Pet self)
|
|
|
|
|
{
|
|
|
|
|
if (self.petState is not (Pet.PetState.Idle))
|
|
|
|
|
{
|
|
|
|
|
return "行动中";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerData data = self.Parent.GetComponent<PlayerData>();
|
|
|
|
|
if (data.petActive <= 0) return "活跃度不足";
|
|
|
|
|
|
|
|
|
|
const int index = (int) PetExploreConfigCategory.PetActionType.Play;
|
|
|
|
|
var configList = PetExploreConfigCategory.Instance.GetListByType((PetExploreConfigCategory.PetActionType) index);
|
|
|
|
|
int petActionIndexFlag = IntFlagHelper.GetFlag(data.petActionIndexFlag, index - 1, 2);
|
|
|
|
|
if (petActionIndexFlag >= configList.Count)
|
|
|
|
|
return "次数达到上限";
|
|
|
|
|
PetExploreConfig config = configList[petActionIndexFlag];
|
|
|
|
|
self.actionEndTime = Game.TimeInfo.ClientNow() + config.Time;
|
|
|
|
|
data.petActive--;
|
|
|
|
|
self.petState = Pet.PetState.Play;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 锻炼
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="self"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string Experience(this Pet self)
|
|
|
|
|
{
|
|
|
|
|
if (self.petState is not (Pet.PetState.Idle))
|
|
|
|
|
{
|
|
|
|
|
return "行动中";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerData data = self.Parent.GetComponent<PlayerData>();
|
|
|
|
|
if (data.petActive <= 0) return "活跃度不足";
|
|
|
|
|
|
|
|
|
|
const int index = (int) PetExploreConfigCategory.PetActionType.Experience;
|
|
|
|
|
var configList = PetExploreConfigCategory.Instance.GetListByType((PetExploreConfigCategory.PetActionType) index);
|
|
|
|
|
int petActionIndexFlag = IntFlagHelper.GetFlag(data.petActionIndexFlag, index - 1, 2);
|
|
|
|
|
if (petActionIndexFlag >= configList.Count)
|
|
|
|
|
return "次数达到上限";
|
|
|
|
|
PetExploreConfig config = configList[petActionIndexFlag];
|
|
|
|
|
self.actionEndTime = Game.TimeInfo.ClientNow() + config.Time;
|
|
|
|
|
data.petActive--;
|
|
|
|
|
self.petState = Pet.PetState.Experience;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetActionReword(this Pet self, PetExploreConfigCategory.PetActionType type)
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case PetExploreConfigCategory.PetActionType.None:
|
|
|
|
|
break;
|
|
|
|
|
case PetExploreConfigCategory.PetActionType.Explore:
|
|
|
|
|
if (self.petState != Pet.PetState.Explore)
|
|
|
|
|
return "宠物没有开始此玩法呢";
|
|
|
|
|
break;
|
|
|
|
|
case PetExploreConfigCategory.PetActionType.Play:
|
|
|
|
|
if (self.petState != Pet.PetState.Play)
|
|
|
|
|
return "宠物没有开始此玩法呢";
|
|
|
|
|
break;
|
|
|
|
|
case PetExploreConfigCategory.PetActionType.Experience:
|
|
|
|
|
if (self.petState != Pet.PetState.Experience)
|
|
|
|
|
return "宠物没有开始此玩法呢";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof (type), type, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long now = TimeHelper.ClientNow();
|
|
|
|
|
if (now < self.actionEndTime)
|
|
|
|
|
return "宠物忙碌中!";
|
|
|
|
|
Unit unit = self.GetParent<Unit>();
|
|
|
|
|
PlayerData data = unit.GetComponent<PlayerData>();
|
|
|
|
|
int index = (int) type;
|
|
|
|
|
var configList = PetExploreConfigCategory.Instance.GetListByType((PetExploreConfigCategory.PetActionType) index);
|
|
|
|
|
int petActionIndexFlag = IntFlagHelper.GetFlag(data.petActionIndexFlag, index - 1, 2);
|
|
|
|
|
if (petActionIndexFlag >= configList.Count)
|
|
|
|
|
return "系统错误,次数达到上限";
|
|
|
|
|
PetExploreConfig config = configList[petActionIndexFlag];
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case PetExploreConfigCategory.PetActionType.None:
|
|
|
|
|
break;
|
|
|
|
|
case PetExploreConfigCategory.PetActionType.Explore:
|
|
|
|
|
//给掉落
|
|
|
|
|
using (UnOrderMultiMapComponent<long, (int, int)> rewordMapComponent = UnOrderMultiMapComponent<long, (int, int)>.Create())
|
|
|
|
|
{
|
|
|
|
|
int parentId= config.EndRewordArr.FirstOrDefault(t => t.PetId == self.petId).IncressValue;
|
|
|
|
|
if (parentId == 0) return "系统错误";
|
|
|
|
|
DropHelper.Drop(unit, data, BattleType.None, parentId, rewordMapComponent.MultiMap, 1, "宠物探险",
|
|
|
|
|
false);
|
|
|
|
|
using ListComponent<string> listComponent = ListComponent<string>.Create();
|
|
|
|
|
foreach (KeyValuePair<long, List<(int, int)>> kp in rewordMapComponent.MultiMap.GetDictionary())
|
|
|
|
|
{
|
|
|
|
|
foreach ((int id, int count) in kp.Value)
|
|
|
|
|
{
|
|
|
|
|
listComponent.List.Add($"[color=#ffff00][/color]获得了[color=#226655]{BagHelper.GetName(id)}x{count}[/color]");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Chat.Instance.SendSystemCahtNoBrocast(unit, listComponent.List);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case PetExploreConfigCategory.PetActionType.Play:
|
|
|
|
|
//给亲密度
|
|
|
|
|
self.AddIntimacy(config.EndRewordArr[0].IncressValue);
|
|
|
|
|
break;
|
|
|
|
|
case PetExploreConfigCategory.PetActionType.Experience:
|
|
|
|
|
//给经验
|
|
|
|
|
self.AddExp(config.EndRewordArr[0].IncressValue);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof (type), type, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.petState = Pet.PetState.Idle;
|
|
|
|
|
petActionIndexFlag++;
|
|
|
|
|
IntFlagHelper.SetFlagValue(ref data.petActionIndexFlag, index - 1, petActionIndexFlag, 2);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2021-04-08 20:09:59 +08:00
|
|
|
|
}
|
2021-04-15 00:12:07 +08:00
|
|
|
|
}
|