67 lines
2.4 KiB
C#
Executable File
67 lines
2.4 KiB
C#
Executable File
using Cal.DataTable;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace ET
|
|
{
|
|
public class MapCoinComponentAwakeSystem : AwakeSystem<MapCoinComponent>
|
|
{
|
|
public override void Awake(MapCoinComponent self)
|
|
{
|
|
self.Awake();
|
|
}
|
|
}
|
|
public static class MapCoinComponentSystem
|
|
{
|
|
public static void Awake(this MapCoinComponent self)
|
|
{
|
|
MapCoinComponent.instance = self;
|
|
Refresh(self);
|
|
self.timerId = TimerComponent.Instance.NewRepeatedTimer(60 * 60 * 1000,self.Refresh);
|
|
}
|
|
|
|
private static void Refresh(this MapCoinComponent self)
|
|
{
|
|
self.coinMonsterMapDic.Clear();
|
|
List<int> arr = self.GetParent<MapSceneComponent>().GetAllMapId().ToList();
|
|
RandomHelper.SelectRandom(arr, MathHelper.RoundToInt(arr.Count / 4f));
|
|
foreach (int item in arr)
|
|
{
|
|
MapMonsterConfig mapMonsterConfig = MapMonsterConfigCategory.Instance.Get(MapMonsterConfigId.CoinMonster);
|
|
Unit coinMonster = EntityFactory.Create<Unit, UnitType>(self.DomainScene(), UnitType.Monster);
|
|
coinMonster.AddComponent<ConfigIdComponent>().configId = mapMonsterConfig.Id;
|
|
UnitScene coinUnitScene = coinMonster.AddComponent<UnitScene>();
|
|
coinUnitScene.Position = new UnityEngine.Vector2(mapMonsterConfig.X, mapMonsterConfig.Y);
|
|
self.coinMonsterMapDic.TryAdd(item,coinMonster);
|
|
}
|
|
}
|
|
public static bool HasCoinMonster(this MapCoinComponent self,int mapId)
|
|
{
|
|
return self.coinMonsterMapDic.ContainsKey(mapId);
|
|
}
|
|
public static Unit GetCoinMonster(this MapCoinComponent self, int mapId)
|
|
{
|
|
self.coinMonsterMapDic.TryGetValue(mapId, out Unit unit);
|
|
return unit;
|
|
}
|
|
public static void RemoveMonster(this MapCoinComponent self, long id, int mapId)
|
|
{
|
|
if(self.coinMonsterMapDic.TryGetValue(mapId,out Unit unit))
|
|
{
|
|
if (unit)
|
|
{
|
|
Game.EventSystem.Publish(new ET.EventType.OnDisposeUnit
|
|
{
|
|
Actor_UnitId=id,
|
|
unitId=unit.Id
|
|
}).Coroutine();
|
|
unit.Dispose();
|
|
}
|
|
}
|
|
self.coinMonsterMapDic.Remove(mapId);
|
|
}
|
|
|
|
}
|
|
}
|