2021-04-08 20:09:59 +08:00
|
|
|
|
using Cal.DataTable;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public class AutoBattleIdleComponentAwakeSystem : AwakeSystem<AutoBattleIdleComponent, Team>
|
|
|
|
|
{
|
|
|
|
|
public override void Awake(AutoBattleIdleComponent self, Team team)
|
|
|
|
|
{
|
|
|
|
|
self.team = team;
|
|
|
|
|
self.lastTime = TimeHelper.ClientNow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class AutoBattleIdleComponentUpdateSystem : UpdateSystem<AutoBattleIdleComponent>
|
|
|
|
|
{
|
|
|
|
|
public override void Update(AutoBattleIdleComponent self)
|
|
|
|
|
{
|
|
|
|
|
self.Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class AutoBattleIdleComponentDestroySystem : DestroySystem<AutoBattleIdleComponent>
|
|
|
|
|
{
|
|
|
|
|
public override void Destroy(AutoBattleIdleComponent self)
|
|
|
|
|
{
|
|
|
|
|
self.mapId = 0;
|
|
|
|
|
self.sceneId = 0;
|
|
|
|
|
self.isFight = false;
|
|
|
|
|
self.lastTime = 0;
|
|
|
|
|
self.team = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static class AutoBattleIdleComponentSystem
|
|
|
|
|
{
|
|
|
|
|
private const int fightInterval = 6 * 1000;
|
|
|
|
|
public static void Init(this AutoBattleIdleComponent self, int sceneId)
|
|
|
|
|
{
|
|
|
|
|
self.sceneId = sceneId;
|
|
|
|
|
self.mapId = sceneId * 100 + 1;
|
|
|
|
|
}
|
|
|
|
|
public static void SetFightEnd(this AutoBattleIdleComponent self)
|
|
|
|
|
{
|
|
|
|
|
self.mapId++;
|
|
|
|
|
if (self.mapId % 100 > 10)
|
|
|
|
|
{
|
|
|
|
|
self.ReSet();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self.isFight = false;
|
|
|
|
|
self.lastTime = TimeHelper.ClientNow();
|
|
|
|
|
}
|
|
|
|
|
public static void ReSet(this AutoBattleIdleComponent self)
|
|
|
|
|
{
|
|
|
|
|
self.mapId = self.sceneId * 100 + 1;
|
|
|
|
|
self.isFight = false;
|
|
|
|
|
self.lastTime = TimeHelper.ClientNow();
|
|
|
|
|
}
|
|
|
|
|
public static void Update(this AutoBattleIdleComponent self)
|
|
|
|
|
{
|
|
|
|
|
if (self.team)
|
|
|
|
|
{
|
|
|
|
|
if (!self.isFight)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
long now = TimeHelper.ClientNow();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (now - self.lastTime > fightInterval)
|
|
|
|
|
{
|
|
|
|
|
self.lastTime = now;
|
|
|
|
|
self.isFight = true;
|
|
|
|
|
StartFight(self);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void StartFight(this AutoBattleIdleComponent self)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
MainStory mainStory = MainStoryMap.Instance.GetMainStoryData(self.mapId);
|
|
|
|
|
if (mainStory == null)
|
|
|
|
|
{
|
|
|
|
|
self.isFight = false;
|
|
|
|
|
self.lastTime = TimeHelper.ClientNow();
|
|
|
|
|
Log.Error($"mainStory==null where id = {self.mapId}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
IdleBattle idleBattle = BattleMgrCompnent.Instance.CreateBattle<IdleBattle>(self.team);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
idleBattle.Init(mainStory);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|