private void CreateBuyButton(Vector2 position, string texture, ArmyPrice armyPrice) { IGameEntityFactory factory = (IGameEntityFactory)Parent.Scene.EntityFactory; IMapService mapService = Parent.Scene.ServiceProvider.GetService <IMapService>(); var buyButton = factory.CreateBuyButton(position, new Vector2(mapService.Width * 0.085f), texture, () => BuyArmy(armyPrice)); buyButton.AddChild(factory.CreateIngot(buyButton.Position - new Vector2(mapService.Width * 0.02f, mapService.Height * -0.1f), new Vector2(mapService.Width * 0.035f))); buyButton.AddChild(factory.CreateTextDisplay(buyButton.Position - new Vector2(mapService.Width * -0.01f, mapService.Height * -0.1f), new Vector2(mapService.Width * 0.035f), (int)armyPrice + string.Empty, Color.Black)); buyButtons.Add(buyButton); }
public void BuyArmy(ArmyPrice armyPrice) { if (Parent.GetComponent <OwnerComponent>().Owner == 0) { Parent.GetComponent <SelectComponent>().Selected = true; } int owner = Parent.GetComponent <OwnerComponent>().Owner; IGoldService goldService = Parent.Scene.ServiceProvider.GetService <IGoldService>(); int gold = goldService.GetGold(owner); if (gold < (int)armyPrice) { return; } goldService.RemoveGold(owner, (int)armyPrice); IGameEntityFactory factory = (IGameEntityFactory)Parent.Scene.EntityFactory; IEntity entity = null; switch (armyPrice) { case ArmyPrice.Archer: if (Parent.GetComponent <OwnerComponent>().Owner == 0) { Parent.Scene.ServiceProvider.GetService <IAudioService>().PlaySound("intro"); } entity = factory.CreateArcher(Parent.Position, owner, 0); break; case ArmyPrice.Knight: if (Parent.GetComponent <OwnerComponent>().Owner == 0) { Parent.Scene.ServiceProvider.GetService <IAudioService>().PlaySound("intro"); } entity = factory.CreateKnight(Parent.Position, owner, 0); break; case ArmyPrice.Catapult: if (Parent.GetComponent <OwnerComponent>().Owner == 0) { Parent.Scene.ServiceProvider.GetService <IAudioService>().PlaySound("intro"); } entity = factory.CreateCatapult(Parent.Position, owner, 0); break; } if (entity != null) { new MoveRandomComponent(entity); } }
private void LoadGameObject(IMapObject o) { IGameEntityFactory gameFactory = (IGameEntityFactory)EntityFactory; var goldValue = 0; if (o.Properties.ContainsKey("goldValue")) { goldValue = int.Parse(o.Properties["goldValue"]); } switch (o.Name.ToLower()) { case "army": switch (int.Parse(o.Properties["type"])) { case 0: gameFactory.CreateArcher(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"]), goldValue); break; case 1: gameFactory.CreateKnight(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"]), goldValue); break; case 2: gameFactory.CreateCatapult(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"]), goldValue); break; default: break; } break; case "tower": gameFactory.CreateTower(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"]), goldValue); break; case "fortress": gameFactory.CreateFortress(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"]), goldValue); break; case "spawnpoint": gameFactory.CreateSpawnpoint(new Vector2(o.X, o.Y), int.Parse(o.Properties["owner"])); break; default: break; } }
public PetEventHandler(INpcMonsterService npcMonsterService, IGameEntityFactory entityFactory) { _npcMonsterService = npcMonsterService; _entityFactory = entityFactory; }
void Start() { gameEntityFactory = (IGameEntityFactory)GameComponent.Get<IGameEntityFactory>("GameEntityFactory"); EntityTracking.Register(this); }