protected override void OnUpdate() { if (!EntityManager.World.GetExistingSystem <GameStateSystem>().IsInGame) { return; } int2 playerPos = int2.zero; int viewDepth = 0; Entities.WithAll <Player>().ForEach((Entity e, ref WorldCoord coord, ref Sight sight) => { playerPos = new int2(coord.x, coord.y); viewDepth = sight.SightRadius; }); GameStateSystem gss = EntityManager.World.GetExistingSystem <GameStateSystem>(); View view = gss.View; bool[] blockedPosition = new bool[view.Height * view.Width]; Entities.WithAll <BlockMovement>().ForEach((Entity e, ref WorldCoord coord) => { int i = View.XYToIndex(new int2(coord.x, coord.y), view.Width); blockedPosition[i] = true; }); // Determine whether tile is visible to Player Entities.ForEach((Entity e, ref WorldCoord coord) => { int2 pos = new int2(coord.x, coord.y); int tileIndex = View.XYToIndex(pos, view.Width); Tile tile = EntityManager.GetComponentData <Tile>(view.ViewTiles[tileIndex]); float totalDistance = math.sqrt(math.pow(math.distance(playerPos.x, pos.x), 2) + math.pow(math.distance(playerPos.y, pos.y), 2)); if (totalDistance <= viewDepth && !SightBlocked(playerPos, pos, view, blockedPosition)) { tile.IsSeen = true; tile.HasBeenRevealed = true; } else { tile.IsSeen = false; } EntityManager.SetComponentData(view.ViewTiles[tileIndex], tile); }); }
protected override void OnCreate() { base.OnCreate(); _gss = EntityManager.World.GetOrCreateSystem <GameStateSystem>(); _tms = EntityManager.World.GetOrCreateSystem <TurnManagementSystem>(); _inv = EntityManager.World.GetOrCreateSystem <InventorySystem>(); ResizeMaps(_gss.View.Width, _gss.View.Height); var query = new EntityQueryDesc { All = new ComponentType[] { ComponentType.ReadOnly <BlockMovement>(), ComponentType.ReadOnly <WorldCoord>() } }; _mapFillQuery = GetEntityQuery(query); }
protected override void OnUpdate() { LogSystem log = EntityManager.World.GetExistingSystem <LogSystem>(); GameStateSystem gss = EntityManager.World.GetExistingSystem <GameStateSystem>(); TurnManagementSystem tms = EntityManager.World.GetExistingSystem <TurnManagementSystem>(); View view = gss.View; Entity[] healingItems = new Entity[view.Width * view.Height]; Entities.WithAll <HealItem>().ForEach((Entity e, ref WorldCoord coord) => { int i = View.XYToIndex(new int2(coord.x, coord.y), view.Width); healingItems[i] = e; }); Entities.WithAll <Player>().ForEach((Entity e, ref WorldCoord coord, ref HealthPoints hp) => { int i = View.XYToIndex(new int2(coord.x, coord.y), view.Width); if (EntityManager.HasComponent(healingItems[i], typeof(HealItem))) { HealItem heal = EntityManager.GetComponentData <HealItem>(healingItems[i]); if (hp.now + heal.HealAmount > hp.max) { heal.HealAmount = (hp.max - hp.now); } hp.now += heal.HealAmount; if (heal.HealAmount > 0) { log.AddLog($"Healed for {heal.HealAmount.ToString()} points."); } else if (heal.HealAmount == 0) { log.AddLog("Healed for 0 points. ...that's disappointing."); } else if (heal.HealAmount < 0) { string dmgLog = $"The Kobolds have poisoned the potion!! {(-1 * heal.HealAmount).ToString()} damage taken!"; log.AddLog(dmgLog); gss.LastPlayerHurtLog = dmgLog; } PostUpdateCommands.DestroyEntity(healingItems[i]); } }); }