/// <summary> /// When entity wants to attack, we need to check whether the attack is blocked in some way /// </summary> /// <param name="gameEvent"></param> private void EntityRequestAttack(EntityRequestAttackEvent gameEvent) { var entity = (Entity)gameEvent.EventParams[0]; var invComp = entity.GetComponent <InventoryComponent>(); var damage = 1; if (invComp != null) { var item = invComp.GetActiveItem(); if (item != null) { var weapon = item as Weapon; if (weapon != null) { damage = weapon.Damage; } } } var targetX = (int)gameEvent.EventParams[1]; var targetY = (int)gameEvent.EventParams[2]; var entPos = entity.GetComponent <PositionComponent>(); var startingX = entPos.ComponentXPositionOnMap; var startingY = entPos.ComponentYPositionOnMap; // Gives us true target co-ordinates, if path to target is obscured target will be the obstruction var path = PlotCourse(entity, new Vector2i(startingX, startingY), new Vector2i(targetX, targetY)); var attackX = path[path.Count - 1].X; var attackY = path[path.Count - 1].Y; SystemManager.BroadcastEvent(new EntityAttackCoordsEvent(entity, damage, attackX, attackY)); }
private void EntityAttackCoords(EntityAttackCoordsEvent gameEvent) { var entityAttacking = (Entity)gameEvent.EventParams[0]; int baseDamage = (int)gameEvent.EventParams[1]; int targetX = (int)gameEvent.EventParams[2]; int targetY = (int)gameEvent.EventParams[3]; var entityAttacked = _systemEntities.Where(ent => ent.GetComponent <PositionComponent>().ComponentXPositionOnMap == targetX && ent.GetComponent <PositionComponent>().ComponentYPositionOnMap == targetY).FirstOrDefault(); if (entityAttacked == null) { return; } Console.WriteLine($"Attack succeeded, changing HP by {baseDamage}"); SystemManager.BroadcastEvent(new ChangeEntityHealthEvent(entityAttacked.Id, baseDamage * -1)); SystemManager.BroadcastEvent(new AddGameLogMessageEvent($"<C=#FFFF00ff>{entityAttacking.Name}</C> did <C=#FF0000ff>{baseDamage}</C> damage to <C=#FFFF00ff>{entityAttacked.Name}</C>")); }
public override void HandleMessage(IGameEvent gameEvent) { switch (gameEvent.EventName) { case "RequestActiveItem": { var id = (Guid)gameEvent.EventParams[0]; SystemManager.BroadcastEvent(new SendActiveItemEvent(GetActiveItemForEntity(id))); break; } case "ChangeActiveItem": { var id = (Guid)gameEvent.EventParams[0]; var ent = _systemEntities.Where(e => e.Id == id).FirstOrDefault(); if (ent != null) { ent.GetComponent <InventoryComponent>().IncrementActiveItem(); } break; } } }
private void PlayerRequestAttack() { var mainChar = _gameStateHelper.GetVar <ActorEntity>("MainEntity"); SystemManager.BroadcastEvent(new EntityRequestAttackEvent(mainChar, _targetedCoords.X, _targetedCoords.Y)); }