private void OnCollection(System.Object obj) { CollectableGood collectable = (CollectableGood)obj; BasePlayer player = BasePlayer.getOwner(collectable.entity); ResourcesPlacer.get(player).Collect(collectable.goods.type, collectable.goods.amount); }
private void showActionButtons(System.Object obj) { GameObject objeto = (GameObject)obj; IGameEntity entity = objeto.GetComponent <IGameEntity>(); GameObject actionPanel = GameObject.Find("HUD/actions"); actionPanel.GetComponent <Image>().enabled = true; var abilities = entity.info.abilities; var nabilities = abilities.Count; //abilities_on_show.Clear(); buttons_on_show.Clear(); affordable_buttons.Clear(); for (int i = 0; i < nabilities; i++) { GameObject button = GameObject.Find("Button " + i); String ability = abilities[i].name; Ability abilityObj = entity.getAbility(ability); if (button == null) { continue; } // fix to avoid nullreference Button buttonComponent = button.GetComponent <Button>(); var image = buttonComponent.GetComponent <Image>(); var eventTrigger = button.GetComponent <EventTrigger>(); buttonComponent.onClick.RemoveAllListeners(); if (abilityObj.isUsable && !abilityObj.isActive) { if (ResourcesPlacer.get(BasePlayer.player).enoughResources(abilityObj._info)) { UnityAction actionMethod = new UnityAction(() => { Debug.Log("* " + abilityObj); abilityObj.enable(); }); image.name = ability; image.sprite = CreateSprite(ability, image.rectTransform.sizeDelta); buttonComponent.targetGraphic = image; buttonComponent.onClick.AddListener(() => actionMethod()); image.enabled = true; eventTrigger.enabled = true; buttonComponent.interactable = true; } //if (entity.info.resources.food < BasePlayer.player.resources.getAmount(WorldResources.Type.FOOD)) //{ // Debug.LogError("General food quantity: " + BasePlayer.player.resources.getAmount(WorldResources.Type.FOOD)); //} // HACK: When this is fired, the button status should be updated! abilityObj.isActive might have changed... } bool interactable = ResourcesPlacer.get(BasePlayer.player).enoughResources(abilityObj.info <Storage.EntityAbility>()); affordable_buttons[abilityObj] = interactable; buttonComponent.interactable = interactable; buttons_on_show.Add(buttonComponent); } }
/// <summary> /// Need to unify this method with players one. /// </summary> /// <param name="race"></param> /// <param name="type"></param> /// <returns></returns> public bool isAffordable(Storage.Races race, Storage.BuildingTypes type) { Storage.BuildingInfo i = Storage.Info.get.of(race, type); return(ResourcesPlacer.get(BasePlayer.ia).enoughResources(WorldResources.Type.FOOD, i.resources.food) && ResourcesPlacer.get(BasePlayer.ia).enoughResources(WorldResources.Type.WOOD, i.resources.wood) && ResourcesPlacer.get(BasePlayer.ia).enoughResources(WorldResources.Type.METAL, i.resources.metal)); }
private void BuildDefences() { if (ResourcesPlacer.get(BasePlayer.ia).Amount(WorldResources.Type.WOOD) > 400) { for (int i = 0; i < (ai.DifficultyLvl * 3); i++) { architect.addDefence(); } } }
public void ControlButtonsInteractability() { for (int i = 0; i < abilities_on_show.Count; i++) { Button b = buttons_on_show[i]; bool interactable = ResourcesPlacer.get(BasePlayer.player).enoughResources(abilities_on_show[i].info <Storage.EntityAbility>()); b.interactable = interactable; affordable_buttons[abilities_on_show[i]] = interactable; } }
private void OnNewExplorer(System.Object obj) { IGameEntity entity = (IGameEntity)obj; if (BasePlayer.getOwner(entity).Equals(BasePlayer.player)) { PopulationInfo.get.RemoveWorker(); } ResourcesPlacer.get(BasePlayer.getOwner(entity)).StatisticsChanged(entity, CreatePackageFromEntity(entity)); }
/// <summary> /// Shows the resources of the AI in order to check if AI is spending money /// </summary> /// <param name="windowID"></param> void showResources(int windowID) { GUI.contentColor = Color.red; GUI.Label(new Rect(marginLeft, 20, textWidth, textHeight), "Food: " + ResourcesPlacer.get(BasePlayer.ia).Amount(WorldResources.Type.FOOD).ToString()); GUI.contentColor = Color.white; GUI.Label(new Rect(marginLeft, 40, textWidth, textHeight), "Wood: " + ResourcesPlacer.get(BasePlayer.ia).Amount(WorldResources.Type.WOOD).ToString()); GUI.contentColor = Color.yellow; GUI.Label(new Rect(marginLeft, 60, textWidth, textHeight), "Gold: " + ResourcesPlacer.get(BasePlayer.ia).Amount(WorldResources.Type.GOLD).ToString()); GUI.contentColor = Color.cyan; GUI.Label(new Rect(marginLeft, 80, textWidth, textHeight), "Metal: " + ResourcesPlacer.get(BasePlayer.ia).Amount(WorldResources.Type.METAL).ToString()); GUI.DragWindow(); }
/// <summary> /// Pops a unit from the queue, preventing it from being created /// </summary> public void cancelUnitQueue() { if (_creationQueue.Count > 0) { IGameEntity entity = gameObject.GetComponent <IGameEntity>(); UnitInfo unitInfo = Info.get.of(info.race, (UnitTypes)_creationQueue.Dequeue()); _creatingUnit = false; BasePlayer player = BasePlayer.getOwner(entity); ResourcesPlacer.get(player).Collect(WorldResources.Type.WOOD, unitInfo.resources.wood); ResourcesPlacer.get(player).Collect(WorldResources.Type.METAL, unitInfo.resources.metal); ResourcesPlacer.get(player).Collect(WorldResources.Type.FOOD, unitInfo.resources.food); } }
void showActions(System.Object obj) { GameObject gameObject = (GameObject)obj; GameObject actionPanel = GameObject.Find("HUD/actions"); if (!actionPanel) { return; } IGameEntity entity = gameObject.GetComponent <IGameEntity>(); var rectTransform = actionPanel.GetComponent <RectTransform>(); var size = rectTransform.sizeDelta; var globalScaleXY = new Vector2(rectTransform.lossyScale.x, rectTransform.lossyScale.y); var extents = Vector2.Scale(size, globalScaleXY) / 2.0f; var buttonExtents = new Vector2(extents.x / Button_Columns, extents.y / Button_Rows); var position = rectTransform.position; var point = new Vector2(position.x - extents.x, position.y + extents.y); var abilities = entity.info.abilities; var nabilities = abilities.Count; abilities_on_show.Clear(); buttons_on_show.Clear(); affordable_buttons.Clear(); for (int i = 0; i < nabilities; i++) { String ability = abilities[i].name; Ability abilityObj = entity.getAbility(ability); abilities_on_show.Add(abilityObj); if (abilityObj.isUsable) { // HACK: When this is fired, the button status should be updated! abilityObj.isActive might have changed... UnityAction actionMethod = new UnityAction(() => { Debug.Log(abilityObj); abilityObj.enable(); }); var buttonCenter = point + buttonExtents * (2 * (i % Button_Columns) + 1); buttonCenter.y = point.y - (buttonExtents.y * (2 * (i / Button_Columns) + 1)); bool interactable = ResourcesPlacer.get(BasePlayer.player).enoughResources(abilities_on_show[i].info <Storage.EntityAbility>()); affordable_buttons[abilityObj] = interactable; Button b = CreateButton(rectTransform, buttonCenter, buttonExtents, ability, actionMethod, !abilityObj.isActive); b.interactable = interactable; buttons_on_show.Add(b); } } }
private void OnDestroyed(System.Object obj) { IGameEntity entity = (IGameEntity)obj; BasePlayer owner = BasePlayer.getOwner(entity); ResourcesPlacer placer = ResourcesPlacer.get(owner); if (entity.info.isUnit) { Unit unit = (Unit)entity; placer.RemoveEntity(WorldResources.Type.FOOD, entity); } else if (((BuildingInfo)entity.info).type != BuildingTypes.STRONGHOLD) { Resource resource = (Resource)entity; placer.RemoveEntity(GetElementFromResource(resource), entity); } placer.updatePopulation(); }
public override void enable() { // Give resources back IGameEntity entity = _gameObject.GetComponent <IGameEntity>(); EntityResources resources = entity.info.buildingAttributes.sellValue; if (resources != null) { BasePlayer player = BasePlayer.getOwner(entity); ResourcesPlacer.get(player).Collect(WorldResources.Type.FOOD, resources.food); ResourcesPlacer.get(player).Collect(WorldResources.Type.WOOD, resources.wood); ResourcesPlacer.get(player).Collect(WorldResources.Type.METAL, resources.metal); } else { Debug.LogWarning(entity + " Have no sellValue on JSON"); } BasePlayer.player.selection.deselectBuilding(); _gameObject.GetComponent <IGameEntity>().Destroy(true); _enabled = true; base.enable(); }
private void OnCreated(System.Object obj) { IGameEntity entity = (IGameEntity)obj; EntityResources res = entity.info.resources; Dictionary <WorldResources.Type, float> d = new Dictionary <WorldResources.Type, float>() { { WorldResources.Type.FOOD, res.food }, { WorldResources.Type.WOOD, res.wood }, { WorldResources.Type.METAL, res.metal } }; BasePlayer owner = BasePlayer.getOwner(entity); ResourcesPlacer placer = ResourcesPlacer.get(owner); bool isUnit = entity.doIfUnit(unit => { if (unit.type != UnitTypes.HERO) { placer.Buy(d); } }); if (!isUnit) { if (((BuildingInfo)entity.info).type != BuildingTypes.STRONGHOLD) { placer.Buy(d); } } placer.updatePopulation(); if (entity.info.isResource || entity.info.isUnit) { placer.StatisticsChanged(entity, CreatePackageFromEntity(entity)); } }
// Use this for initialization public override void Start() { base.Start(); _selection = GetComponent <Managers.SelectionManager>(); //request the race of the player _selfRace = info.GetPlayerRace(); _selection.SetRace(race); cam = GameObject.FindWithTag("MainCamera").GetComponent <CameraController>(); events = GetComponent <EventsNotifier>(); Battle.PlayerInformation me = info.GetBattle().GetPlayerInformationList()[playerId - 1]; InstantiateBuildings(me.GetBuildings()); InstantiateUnits(me.GetUnits()); SetInitialResources(me.GetResources().Wood, me.GetResources().Food, me.GetResources().Metal, me.GetResources().Gold); // gameObject.AddComponent<ResourcesPlacer>(); missionStatus = new MissionStatus(playerId); _resourcesPlacer = ResourcesPlacer.get(this); // initialization // TODO Set this values dynamically minFoodTolerance = 100; minWoodTolerance = 500; minMetalTolerance = 500; minGoldTolerance = 500; foodDepleted = _resourcesPlacer.Amount(WorldResources.Type.FOOD) <= 0; ActorSelector selector = new ActorSelector() { registerCondition = (g) => !(g.GetComponent <FOWEntity>().IsOwnedByPlayer), fireCondition = (g) => true }; Utils.Subscriber <FOWEntity.Actions, FOWEntity> .get.registerForAll(FOWEntity.Actions.DISCOVERED, OnEntityFound, selector); timeToShow = WAIT_FOR_FINISH; }
public bool isAffordable(Storage.Races race, Storage.BuildingTypes type) { Storage.BuildingInfo i = Storage.Info.get.of(race, type); return(ResourcesPlacer.get(BasePlayer.player).enoughResources(i.resources)); }
public void SetInitialResources(uint wood, uint food, uint metal, uint gold) { // TODO Consider adding a maximum capacity ResourcesPlacer.get(this).InitializeResources(wood, food, metal, gold); }