override public void InitialiseWithBuilding(Building building)
 {
     if (!initialised)
     {
         occupantScrollPanel.GetComponent <UIDraggablePanel>().ResetPosition();
         List <OccupantData> data = building.Occupants;
         occupantViewPanels = new List <UIOccupantViewPanel>();
         if (data != null)
         {
             foreach (OccupantData o in data)
             {
                 AddOccupantPanel(o, false);
             }
         }
         if ((building.CurrentActivity != null && building.CurrentActivity.Type == ActivityType.RECRUIT) || ((building.CompletedActivity != null && building.CompletedActivity.Type == ActivityType.RECRUIT)))
         {
             OccupantData no = new OccupantData();
             no.Type = OccupantManager.GetInstance().GetOccupantTypeData(building.CurrentActivity.SupportingId);
             AddOccupantPanel(no, true);
             // TODO Coroutine to allow constant update of this panel (or maybe it should be in the panel itself?)
         }
         occupantScrollPanel.GetComponent <UIGrid>().Reposition();
         occupantScrollPanel.GetComponent <UIDraggablePanel>().ResetPosition();
         initialised = true;
     }
 }
 /**
  * Set up the occupant with the given data.
  */
 public void InitialiseWithOccupant(OccupantData data, bool inProgress)
 {
     this.data             = data;
     titleLabel.text       = data.Type.name;
     descriptionLabel.text = data.Type.description;
     sprite.spriteName     = data.Type.spriteName;
     if (inProgress)
     {
         dismissButton.gameObject.SetActive(false);
     }
     else
     {
         // Check if unit in battle
         Activity activity = ActivityManager.GetInstance().CheckForActivityById(data.uid);
         if (activity != null)
         {
             // The unit is doing something, show what they are doing
             // Currently only attacking is supported
             if (ActivityManager.GetInstance().GetActivityData(activity.Type) is AttackActivityData)
             {
                 dismissButton.gameObject.SetActive(true);
                 dismissButton.InitAsAttack(activity.PercentageComplete);
             }
             else
             {
                 Debug.LogWarning("Occupant involved in an activity with no corresponding UI");
             }
         }
         else
         {
             dismissButton.gameObject.SetActive(true);
             dismissButton.Init(data);
         }
     }
 }
	/**
	 * Set up the occupant with the given data.
     */
	public void InitialiseWithOccupant(OccupantData data, bool inProgress) {
		this.data = data;
		titleLabel.text = data.Type.name;
		descriptionLabel.text = data.Type.description;
		sprite.spriteName = data.Type.spriteName;
		if (inProgress) {
			dismissButton.gameObject.SetActive(false);
		} else {
			// Check if unit in battle
			Activity activity = ActivityManager.GetInstance().CheckForActivityById(data.uid);
			if (activity != null) {
				// The unit is doing something, show what they are doing
				// Currently only attacking is supported
				if (ActivityManager.GetInstance().GetActivityData(activity.Type) is AttackActivityData) {
					dismissButton.gameObject.SetActive(true);
					dismissButton.InitAsAttack(activity.PercentageComplete);
				
				} else {
					Debug.LogWarning("Occupant involved in an activity with no corresponding UI");
				}
			} else {
				dismissButton.gameObject.SetActive(true);
				dismissButton.Init(data);
			}
		}
	}
    private void AddOccupantPanel(OccupantData data, bool inProgress)
    {
        GameObject          panelGo = (GameObject)NGUITools.AddChild(occupantScrollPanel, occupantPanelPrefab);
        UIOccupantViewPanel panel   = panelGo.GetComponent <UIOccupantViewPanel>();

        panel.InitialiseWithOccupant(data, inProgress);
        occupantViewPanels.Add(panel);
    }
	public void Init(OccupantData occupant) {
		this.occupant = occupant;
		canDismiss = true;
		// icon.spriteName = "cancel_icon";
		ring.color = new Color(1,0,0);
		ring.fillAmount = 1.0f;
		background.fillAmount = 1.0f;
		label.text="DISMISS";
	}
 public void Init(OccupantData occupant)
 {
     this.occupant         = occupant;
     canDismiss            = true;
     icon.spriteName       = "cancel_icon";
     ring.color            = new Color(1, 0, 0);
     ring.fillAmount       = 1.0f;
     background.fillAmount = 1.0f;
     label.text            = "DISMISS";
 }
Example #7
0
 /**
  * Called when a bulding dismissed an occupant.
  */
 public void DismissedOccupant(OccupantData data)
 {
     if (data != null && occupants.ContainsKey(data.uid))
     {
         occupants.Remove(data.uid);
     }
     else
     {
         Debug.LogWarning("Dismissed an occupant that wasn't found");
     }
 }
 /**
  * Dismiss (remove) the occupant. Returns true if occupant found and removed, otherwise false;
  */
 virtual public bool DismissOccupant(OccupantData occupant)
 {
     if (data.occupants != null)
     {
         if (data.occupants.Contains(occupant))
         {
             data.occupants.Remove(occupant);
             OccupantManager.GetInstance().DismissedOccupant(occupant);
             return(true);
         }
     }
     return(false);
 }
    /**
     * Create a new occupant and add it to this building
     */
    protected void CreateOccupant(string supportingId)
    {
        OccupantData occupant = new OccupantData();

        occupant.uid  = System.Guid.NewGuid().ToString();
        occupant.Type = OccupantManager.GetInstance().GetOccupantTypeData(supportingId);
        occupant.occupantTypeString = occupant.Type.id;
        if (data.occupants == null)
        {
            data.occupants = new List <OccupantData>();
        }
        data.occupants.Add(occupant);
        OccupantManager.GetInstance().RecruitedOccupant(occupant);
    }
Example #10
0
 /**
  * Dismiss an occupant by ID, search all building to ensure they are removed. This should
  * only be used when the occupant cant be dismissed at the building level as it is more expensive.
  */
 public void DismissOccupant(string id)
 {
     if (occupants.ContainsKey(id))
     {
         OccupantData    data      = occupants[id];
         List <Building> buildings = BuildingManager.GetInstance().GetAllBuildings();
         foreach (Building b in buildings)
         {
             if (b.Occupants != null && b.Occupants.Contains(data))
             {
                 b.DismissOccupant(data);
                 break;
             }
         }
     }
 }
	override public void InitialiseWithBuilding(Building building) {
		if (!initialised) {
			List <OccupantData> data = building.Occupants;
			occupantViewPanels = new List<UIOccupantViewPanel>();
			occupantScrollPanel.GetComponent<UIScrollView>().ResetPosition();
			if (data != null)  {
				foreach(OccupantData o in data) {
					AddOccupantPanel(o, false);
				}
			}
			if ((building.CurrentActivity != null && building.CurrentActivity.Type == ActivityType.RECRUIT) || ((building.CompletedActivity != null && building.CompletedActivity.Type == ActivityType.RECRUIT) )) {
				OccupantData no = new OccupantData();
				no.Type = OccupantManager.GetInstance().GetOccupantTypeData(building.CurrentActivity.SupportingId);
				AddOccupantPanel(no, true);
				// TODO Coroutine to allow constant update of this panel (or maybe it should be in the panel itself?)
			}
			occupantScrollPanel.GetComponent<UIGrid>().Reposition();
			initialised = true;
		}
	}
	/**
	 * Create a new occupant and add it to this building
	 */ 
	protected void CreateOccupant(string supportingId) {
		OccupantData occupant = new OccupantData();
		occupant.uid = System.Guid.NewGuid().ToString();
		occupant.Type = OccupantManager.GetInstance().GetOccupantTypeData(supportingId);
		occupant.occupantTypeString = occupant.Type.id;
		if (data.occupants == null) data.occupants = new List<OccupantData>();
		data.occupants.Add (occupant);
		OccupantManager.GetInstance().RecruitedOccupant(occupant);
	}
	private void AddOccupantPanel(OccupantData data, bool inProgress) {
		GameObject panelGo = (GameObject) NGUITools.AddChild(occupantScrollPanel, occupantPanelPrefab);
		UIOccupantViewPanel panel = panelGo.GetComponent<UIOccupantViewPanel>();
		panel.InitialiseWithOccupant(data, inProgress);
		occupantViewPanels.Add (panel);
	}
	virtual protected int AllocateUnitToSpot(OccupantData o) {

		for (int i = 0 ; i < ((BuildingDataWithUnitAnimations)building.Type).animationPositions.Count; i++) {
			if (animators[i].gameObject.activeInHierarchy == false && o.occupantTypeString == "SWORDSMAN") {
				animators[i].gameObject.SetActive(true);
				animators[i].Show ();
				return i;
			}
		}
		for (int i = 0 ; i < ((BuildingDataWithUnitAnimations)building.Type).staticPositions.Count; i++) {
			if (staticUnits[i].gameObject.activeInHierarchy == false ) {
				staticUnits[i].gameObject.SetActive(true);
				staticUnits[i].spriteName = o.Type.spriteName;
				return i + ((BuildingDataWithUnitAnimations)building.Type).animationPositions.Count;
			}
		}
		return -1;
	}
	/**
	 * Dismiss (remove) the occupant. Returns true if occupant found and removed, otherwise false;
	 */ 
	virtual public bool DismissOccupant(OccupantData occupant) {
		if (data.occupants != null)	{
			if (data.occupants.Contains(occupant)) {
				data.occupants.Remove(occupant);
				OccupantManager.GetInstance().DismissedOccupant(occupant);
				view.SendMessage ("UI_DismissOccupant", SendMessageOptions.DontRequireReceiver);
				return true;		
			}
		}
		return false;
	}
    /**
     * Handle the battle results calculations
     */
    public void CustomReward(Activity activity)
    {
        List <string> losses            = new List <string>();
        int           goldRewarded      = 0;
        int           resourcesRewarded = 0;
        ActivityData  type = ActivityManager.GetInstance().GetActivityData(activity.Type);

        if (type is AttackActivityData)
        {
            int troopStrength = 0;
            foreach (string s in activity.SupportingIds)
            {
                OccupantData o = OccupantManager.GetInstance().GetOccupant(s);
                if (o != null && o.Type is AttackerOccupantTypeData)
                {
                    troopStrength += ((AttackerOccupantTypeData)o.Type).attack;
                }
            }
            // Calculate result
            bool winner = false;
            if (troopStrength >= ((AttackActivityData)type).strength * 2)
            {
                winner = true;
                // No losses
            }
            else if (troopStrength >= ((AttackActivityData)type).strength)
            {
                if (Random.Range(0, 3) != 0)
                {
                    winner = true;
                }
                // 25% chance of losing each unit
                losses.AddRange(activity.SupportingIds.Where(o => Random.Range(0, 4) == 0).ToList());
                // Ensure at least one troop member survives
                if (losses.Count == activity.SupportingIds.Count)
                {
                    losses.RemoveAt(0);
                }
            }
            else if (troopStrength >= (int)(((AttackActivityData)type).strength * 0.5f))
            {
                // Calculate losses
                if (Random.Range(0, 3) == 0)
                {
                    winner = true;
                }
                // 50% chance of losing each unit
                losses.AddRange(activity.SupportingIds.Where(o => Random.Range(0, 2) == 0).ToList());
                // Ensure at least one troop member survives
                if (losses.Count == activity.SupportingIds.Count)
                {
                    losses.RemoveAt(0);
                }
            }
            else
            {
                // Lose everyone
                losses.AddRange(activity.SupportingIds);
            }

            // Calculate reward
            if (winner)
            {
                goldRewarded      = Random.Range(0, type.rewardAmount + 1);
                resourcesRewarded = Random.Range(1, type.rewardAmount + 1) * 100;
            }

            // Remove occupants
            string lossesString = "";
            foreach (string o in losses)
            {
                lossesString += OccupantManager.GetInstance().GetOccupant(o).Type.name + ", ";
            }
            foreach (string o in losses)
            {
                OccupantManager.GetInstance().DismissOccupant(o);
            }
            if (lossesString.Length > 0)
            {
                lossesString.Substring(0, lossesString.Length - 2);
            }

            // Add rewards
            ResourceManager.Instance.AddResources(resourcesRewarded);
            ResourceManager.Instance.AddGold(goldRewarded);

            // Show panel -
            UIBattleResultsPanel panel = (UIBattleResultsPanel)FindObjectOfType(typeof(UIBattleResultsPanel));
            if (panel != null)
            {
                panel.InitialiseWithResults(winner, lossesString, goldRewarded, resourcesRewarded);
                UIGamePanel.ShowPanel(PanelType.BATTLE_RESULTS);
            }
        }
    }
Example #17
0
 /**
  * Recruited an occupant.
  */
 public void RecruitedOccupant(OccupantData data)
 {
     occupants.Add(data.uid, data);
 }