68 lines
2.5 KiB
C#
68 lines
2.5 KiB
C#
|
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,()=>Refresh(self));
|
|||
|
}
|
|||
|
|
|||
|
private static void Refresh(MapCoinComponent self)
|
|||
|
{
|
|||
|
self.coinMonsterMapDic.Clear();
|
|||
|
var arr = self.GetParent<MapSceneComponent>().GetAllMapId().ToList();
|
|||
|
RandomHelper.SelectRandom(arr, MathHelper.RoundToInt(arr.Count / 3f));
|
|||
|
foreach (var item in arr)
|
|||
|
{
|
|||
|
MapMonsterConfig mapMonsterConfig = MapMonsterConfigCategory.Instance.Get(MapMonsterConfigId.CoinMonster);
|
|||
|
Unit coinMonster = EntityFactory.Create<Unit, UnitType>(self.DomainScene(), UnitType.MapMonster);
|
|||
|
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);
|
|||
|
}
|
|||
|
Log.Info($"刷新金币怪 {arr.Count}{self.coinMonsterMapDic.Keys.ListToString()}");
|
|||
|
}
|
|||
|
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 var unit);
|
|||
|
return unit;
|
|||
|
}
|
|||
|
public static void RemoveMonster(this MapCoinComponent self, long id, int mapId)
|
|||
|
{
|
|||
|
if(self.coinMonsterMapDic.TryGetValue(mapId,out var unit))
|
|||
|
{
|
|||
|
if (unit)
|
|||
|
{
|
|||
|
Game.EventSystem.Publish(new ET.EventType.OnDisposeUnit
|
|||
|
{
|
|||
|
Actor_UnitId=id,
|
|||
|
unitId=unit.Id
|
|||
|
}).Coroutine();
|
|||
|
unit.Dispose();
|
|||
|
}
|
|||
|
}
|
|||
|
self.coinMonsterMapDic.Remove(mapId);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|