public void PullFlag(GameObject givingObject) { if (givingObject != null) { if (!HolderIsAPlayer && givingObject.GetComponent <TeamID>().TeamIDNumber == ThisHolderTeamID) { FlagHolder givingFlagHolder = givingObject.GetComponent <FlagHolder>(); //Debug.Log("We're the same team"); if (givingFlagHolder != null) { //Debug.Log("Got the holder to pull"); int VictoryCheck = 0; for (int i = 0; i < NumberOfTeams; i++) { if (givingFlagHolder.ListOfLists[i] != null && givingFlagHolder.ListOfLists[i].Count > 0) { //Debug.Log("There's a flag here"); if (ListOfLists[i].Count < NumberOfFlagsPerTeam) { givingFlagHolder.ListOfLists[i][givingFlagHolder.ListOfLists[i].Count - 1].SetActive(false); ListOfLists[i].Add(givingFlagHolder.ListOfLists[i][givingFlagHolder.ListOfLists[i].Count - 1]); FlagsCount++; givingFlagHolder.ListOfLists[i][givingFlagHolder.ListOfLists[i].Count - 1].GetComponent <TeamID>().CurrentFlagBase = this; givingFlagHolder.ListOfLists[i].Remove(givingFlagHolder.ListOfLists[i][givingFlagHolder.ListOfLists[i].Count - 1]); givingFlagHolder.FlagsCount--; if (i % 2 != 0) { ListOfLists[i][ListOfLists[i].Count - 1].transform.position = transform.TransformPoint(new Vector3((float)(FlagPosition.transform.localPosition.x - (((float)i - 1) / 16 + .0625)), FlagPosition.transform.localPosition.y, FlagPosition.transform.localPosition.z + (((float)ListOfLists[i].Count - 1) / 8))); } else { ListOfLists[i][ListOfLists[i].Count - 1].transform.position = transform.TransformPoint(new Vector3((float)(FlagPosition.transform.localPosition.x + ((float)i / 16 + .0625)), FlagPosition.transform.localPosition.y, FlagPosition.transform.localPosition.z + (((float)ListOfLists[i].Count - 1) / 8))); } ListOfLists[i][ListOfLists[i].Count - 1].transform.SetParent(this.transform); ListOfLists[i][ListOfLists[i].Count - 1].transform.rotation = this.transform.rotation; ListOfLists[i][ListOfLists[i].Count - 1].SetActive(true); if (givingFlagHolder.GetComponent <Player>().isAI) { givingFlagHolder.ThisMovementAI.PickABaseToAttack(); } //Debug.Log("Pulled the flag"); } } if (ListOfLists[i].Count >= FlagsFromEachTeamToWin) { VictoryCheck++; //Debug.Log(VictoryCheck + " Victory points"); if (VictoryCheck == 4) { givingObject.GetComponent <Player>().Won(); } } } } } } }
public void GiveFlag(GameObject recievingObject) { //if not same team if (!HolderIsAPlayer && recievingObject.GetComponent <TeamID>().TeamIDNumber != ThisHolderTeamID) { FlagHolder recievingFlagHolder = recievingObject.GetComponent <FlagHolder>(); if (recievingFlagHolder != null) { //Debug.Log("Got the holder"); for (int i = 0; i < NumberOfTeams; i++) { if (recievingFlagHolder.ListOfLists[i].Count == 0) { if (ListOfLists[i].Count > 0) { ListOfLists[i][ListOfLists[i].Count - 1].SetActive(false); recievingFlagHolder.ListOfLists[i].Add(ListOfLists[i][ListOfLists[i].Count - 1]); recievingFlagHolder.FlagsCount++; ListOfLists[i].Remove(ListOfLists[i][ListOfLists[i].Count - 1]); FlagsCount--; recievingFlagHolder.ListOfLists[i][recievingFlagHolder.ListOfLists[i].Count - 1].transform.SetParent(recievingObject.transform); if (i % 2 != 0) { recievingFlagHolder.ListOfLists[i][recievingFlagHolder.ListOfLists[i].Count - 1].transform.localPosition = new Vector3((float)(recievingFlagHolder.FlagPosition.transform.localPosition.x - (((float)i - 1) / 8 + .125)), recievingFlagHolder.FlagPosition.transform.localPosition.y, recievingFlagHolder.FlagPosition.transform.localPosition.z); } else { recievingFlagHolder.ListOfLists[i][recievingFlagHolder.ListOfLists[i].Count - 1].transform.localPosition = new Vector3((float)(recievingFlagHolder.FlagPosition.transform.localPosition.x + ((float)i / 8 + .125)), recievingFlagHolder.FlagPosition.transform.localPosition.y, recievingFlagHolder.FlagPosition.transform.localPosition.z); } recievingFlagHolder.ListOfLists[i][recievingFlagHolder.ListOfLists[i].Count - 1].transform.rotation = recievingObject.transform.rotation; recievingFlagHolder.ListOfLists[i][recievingFlagHolder.ListOfLists[i].Count - 1].SetActive(true); if (recievingFlagHolder.GetComponent <Player>().isAI) { recievingFlagHolder.ThisMovementAI.ReturnToBaseWithFlag(); } } //Debug.Log("Given"); } } } } }