void TerritoryExit(ExposedTrigger sender, ExposedTrigger.TriggerActivityEventArgs e) { Player player = e.gameObject.GetComponent <Player>(); if (player != null) { // Remove the element List <Player> playerList; if (!this.playersCapturing.TryGetValue(player.PlayerTeam, out playerList)) { this.playersCapturing.Add(player.PlayerTeam, playerList = new List <Player>()); } playerList.Remove(player); this.CheckIfPlayerIsCapturing(); // Something changed so maybe someone is capturing } // Fire our own event from this script TerritoryData tData = new TerritoryData(); tData.Progress = this.CaptureProgress; tData.Color = new ColorData(this.LockedCaptureState ? this.LockedCaptureState.ThisTeamToColor() : Player.TeamToColor(Player.Team.None)).ToDictionary(); tData.LockedColor = new ColorData(this.LockedCaptureState ? this.LockedCaptureState.ThisTeamToColor() : Player.TeamToColor(Player.Team.None)).ToDictionary(); tData.TempColor = new ColorData(this.tempCaptureState ? this.tempCaptureState.ThisTeamToColor() : Player.TeamToColor(Player.Team.None)).ToDictionary(); this.OnTerritoryExited(this, new TerritoryActivityEventArgs(player, tData)); }
// Calcule le R0 d'un territoire private float ComputeR0(TerritoryData territoryData) { // Calcul du ratio de personnes infectés parmis les vivants int livingInfected = territoryData.nbInfected - territoryData.nbDeath; int livingPop = territoryData.nbPopulation - territoryData.nbDeath; float infectedRatio = (float)livingInfected / livingPop; // Calcul du R0 théorique float theoreticalR0 = polyA * infectedRatio * infectedRatio + polyB * infectedRatio + polyC; if (theoreticalR0 > 0) { float r0Cumul = 0; // calcule le nouveau R0 (application de bonus et malus) du territoire en fonction de l'age et de la contagiosité théorique for (int age = 0; age < territoryData.numberOfInfectedPeoplePerAgesAndDays.Length; age++) { // aggréger la valeur du R0 pondéré par le nombre de personnes vivante pour l'age considéré r0Cumul += ComputeAgeR0(territoryData, age, theoreticalR0) * (territoryData.popNumber[age] - territoryData.popDeath[age]); } // retourne la moyenne de R0 pour le territoire return(Mathf.Max(0, r0Cumul / livingPop)); } else { return(0); } }
protected override void onStart() { // Récupération des stats du virus virusStats = countrySimData.GetComponent <VirusStats>(); // Récupération des données de la population countryPopData = countrySimData.GetComponent <TerritoryData>(); // Récupération de l'échelle de temps time = countrySimData.GetComponent <TimeScale>(); // calcul de la courbe de mortalité pour une fenêtre de jours deadlinessPerDays = new float[virusStats.windowSize]; float peak = virusStats.deadlinessPeak; float deviation = virusStats.deadlinessDeviation; for (int i = 0; i < deadlinessPerDays.Length; i++) { deadlinessPerDays[i] = (1 / (deviation * Mathf.Sqrt(2 * Mathf.PI))) * Mathf.Exp(-((i - peak) * (i - peak)) / (2 * deviation * deviation)); } // Calcul de la mortalité en fonction de l'age deadlinessPerAges = new float[101]; // Calcul de la valeur de l'exponentielle pour le premier age à partir duquel des morts peuvent arriver float minAgeExpo = Mathf.Exp(virusStats.curveStrenght * ((float)virusStats.firstSensitiveAge / 100 - 1)); // Calcul de la valeur maximale de l'exponentielle pour l'age le plus avancé float maxExpo = 1 - minAgeExpo; // lissage de la mortalité pour quelle soit à 0 au premier age sensible et à sa valeur maximale pour l'age le plus avancé for (int age = 0; age < deadlinessPerAges.Length; age++) { deadlinessPerAges[age] = Mathf.Max(0f, (Mathf.Exp(virusStats.curveStrenght * ((float)age / 100 - 1)) - minAgeExpo) / maxExpo); } }
private void Update() { var trackedPos = transform.position; var gridPoint = TerritoryData.GetGridPosition(trackedPos); bool isAboveBoard = transform.position.y > Consts.PlacementBufferY; // Note this is referring to x and y in 2D space, corresponds to X and Z in 3D space. bool isInXBounds = gridPoint.X >= 0 && gridPoint.X < Consts.GridWidth; bool isInYBounds = gridPoint.Y >= 0 && gridPoint.Y < Consts.GridHeight; var prevIsOverBoard = _isOverBoard; var prevGridPoint = _knownGridPoint; _isOverBoard = isAboveBoard && isInXBounds && isInYBounds; if (_isOverBoard) { _knownGridPoint = gridPoint; _knownWorldPosition = trackedPos; } if (_isOverBoard != prevIsOverBoard || _knownGridPoint.X != prevGridPoint.X || _knownGridPoint.Y != prevGridPoint.Y) { GridSquareChangedEvent.Invoke(); } }
private float GetProtection(int age, TerritoryData territory) { if (territory.closePrimarySchool && age <= 11 || // Vérifier écoles confinées territory.closeSecondarySchool && age > 11 && age <= 15) // Vérifier collèges confinés { return(0.8f); } else if (territory.closeHighSchool && age > 15 && age <= 18) // Vérifier lycées confinés { return(0.7f); // 70 % des lycéens => certains ont déjà quitté le circuit scolaire } else if (territory.closeUniversity && age > 18 && age <= 20) // Vérifier universités confinées { return(0.5f); // 50 % d'une classe d'age a un bac+2 } else if (territory.closeUniversity && age > 20 && age <= 23) // Vérifier universités confinées { return(0.3f); // 30% d'une classe d'age a plus d'un bac+2 } else if (territory.ageDependent && territory.ageDependentMin != "" && territory.ageDependentMax != "" && age >= int.Parse(territory.ageDependentMin) && age <= int.Parse(territory.ageDependentMax)) { return(0.8f); } else { return(0); } }
void Update() { int numImagesUsed = 0; var player = SL.Get <GameModel>().EnemyPlayer; foreach (var building in player.Buildings) { if (building.Entity != null && building.Entity.HP > 0) { foreach (var territory in building.Territory.Territories) { if (numImagesUsed < _imagePool.Count) { var rectTransform = _imagePool[numImagesUsed]; var rect = TerritoryData.ToWorldRect(territory); rectTransform.gameObject.SetActive(true); rectTransform.offsetMin = new Vector2(rect.xMin, rect.yMin); rectTransform.offsetMax = new Vector2(rect.xMax, rect.yMax); numImagesUsed++; } } } } for (int i = numImagesUsed; i < _imagePool.Count; i++) { if (_imagePool[i].gameObject.activeSelf) { _imagePool[i].gameObject.SetActive(false); } } }
void Update() { if (_text != null && _trackedObject != null) { var gridPoint = TerritoryData.GetGridPosition(_trackedObject.transform.position); _text.text = string.Format("Grid : ({0}, {1})", gridPoint.X, gridPoint.Y); } }
void Start() { GetComponent <Image>().alphaHitTestMinimumThreshold = 1f; territory = GetComponent <TerritoryData>(); animator = GetComponent <Animator>(); tooltip = GameObject.Find("TooltipUI").GetComponent <Tooltip>(); audioSource = GameObject.Find("AudioEffects").GetComponentInParent <AudioSource>(); }
void Update() { if (_text != null) { var gridPoint = TerritoryData.GetGridPositionFromMouse(); _text.text = string.Format("({0}, {1})", gridPoint.X, gridPoint.Y); } }
protected override void onStart() { // Récupération des données de la population countryData = countrySimData.GetComponent <TerritoryData>(); // Récupération des données de lits de réa countryBeds = countrySimData.GetComponent <Beds>(); // Récupération de l'échelle de temps time = countrySimData.GetComponent <TimeScale>(); }
public void SkipToBattleHudUI(int skipIndex) { TerritoryData territoryData = NationManager.Instance.TerritoryList.TerritoryList[skipIndex]; if (territoryData.ADType != eTerritoryAttackOrDefendType.None) { GlobalMenuManager.Instance.Open("LTNationBattleHudUI", territoryData); } }
/// <summary> /// Converts a territory definition into world space. /// </summary> /// <param name="territory">The territory to convert.</param> /// <returns>A rectangle in world space on the Y plane.</returns> public static Rect ToWorldRect(TerritoryData territory) { Rect rect = new Rect( territory.StartX * Consts.GridCellWidth, territory.StartY * Consts.GridCellHeight, territory.Width * Consts.GridCellWidth, territory.Height * Consts.GridCellHeight); return(rect); }
// Use this for initialization void Start() { TerritoryData subject = new TerritoryData(); subject.addObserver(new BuildPage(subject)); subject.addObserver(new StatisticPage(subject)); subject.setData(2000, 1000, 3000, 4000); subject.setData(12000, 1000, 13000, 4000); subject.setData(2000, 11000, 3000, 14000); subject.setData(1000, 1000, 1000, 1000); }
public void update() { if (_subject is TerritoryData) { TerritoryData td = _subject as TerritoryData; _people = td.people; _money = td.money; _wood = td.wood; _iron = td.iron; display(); } }
// Use to process your families. protected override void onProcess(int familiesUpdateCount) { if (time.newDay) { foreach (GameObject bedsGO in f_beds) { Beds beds = bedsGO.GetComponent <Beds>(); TerritoryData territory = bedsGO.GetComponent <TerritoryData>(); if (beds.boostBeds) { int newBeds = (beds.intensiveBeds_high - beds.intensiveBeds_current) / 8; // Le 8 permet de ralentir la croissance de la production (le temps de construire/acheter des respirateurs de réorganiser les services, de réquisitionner les hôpitaux et clinique privées...) beds.intensiveBeds_current += newBeds; } // calcul du nombre de lits utilisés : comptabilisation du nombre de personne qui devraient pouvoir accéder à des lits de réanimation, on prend un fenêtre de 9 jours autour du pic de mortalité (même calcul fait dans DeadSystem) int criticAmount = 0; for (int day = Mathf.Max(0, (int)virusStats.deadlinessPeak - 4); day < Mathf.Min(virusStats.deadlinessPeak + 5, territory.numberOfInfectedPeoplePerDays.Length); day++) { criticAmount = (int)(territory.numberOfInfectedPeoplePerDays[day] * virusStats.seriousRatio); } beds.intensiveBeds_need = criticAmount; if (beds.intensiveBeds_need > beds.intensiveBeds_current && beds.advisorNotification == -1 && territory.TerritoryName != "France") { string msgBody = "Attention les hopitaux "; if (territory.TerritoryName == "Mayotte" || territory.TerritoryName == "La Réunion") { msgBody += "à " + territory.TerritoryName; } else { msgBody += "en " + (territory.TerritoryName == "La Corse" ? "Corse" : territory.TerritoryName); } msgBody += " sont dépassés. Il y a trop de cas malades par rapport au nombre de lits de réanimation."; GameObjectManager.addComponent <ChatMessage>(beds.gameObject, new { sender = "Fédération des hôpitaux", timeStamp = "" + time.daysGone, messageBody = msgBody }); beds.advisorNotification = 0; } else if (beds.intensiveBeds_need < beds.intensiveBeds_current && beds.advisorNotification > 10) { beds.advisorNotification = -1; } else if (beds.advisorNotification != -1) { beds.advisorNotification++; } } } }
public void selectTerritory(TerritoryData newTerritory) { if (territorySelected.GetComponent <Animator>() && newTerritory != territorySelected) { territorySelected.GetComponent <Animator>().Play("TerritoryIdle"); } if (newTerritory.GetComponent <Animator>()) { newTerritory.GetComponent <Animator>().Play("TerritorySelected"); } territorySelected = newTerritory; territoryName.text = territorySelected.TerritoryName; SyncUISystem.needUpdate = true; }
// Use to process your families. protected override void onProcess(int familiesUpdateCount) { // Vérifier s'il faut générer une nouvelle journée if (time.newDay) { foreach (GameObject territory in f_territories) { TerritoryData territoryData = territory.GetComponent <TerritoryData>(); Image img = territory.GetComponent <Image>(); float ratio = 1f - 6 * (float)(territoryData.nbInfected - territoryData.nbTreated - territoryData.nbDeath) / (territoryData.nbPopulation - territoryData.nbDeath); img.color = new Color(1f, ratio, ratio); } } }
public void OnTerritoryItemClick(GameObject go) { if (AllianceUtil.GetIsInTransferDart("")) { return; } int index = System.Array.IndexOf(TerritoryGOs, go); TerritoryData territoryData = NationManager.Instance.TerritoryList.TerritoryList[index]; if (territoryData.ADType != eTerritoryAttackOrDefendType.None) { GlobalMenuManager.Instance.Open("LTNationBattleHudUI", territoryData); } }
protected virtual void ThisTerritoryUpdated(MonoBehaviour sender, TerritoryData tData) { TerritoryUpdatedEventHandler handler = OnTerritoryUpdated; if(handler != null) { // Only fire this event every 10nth of a second if(Time.realtimeSinceStartup - this.lastUpdateEventTime > .1f) { // If something has actually updated and not set to the same value as before if(this.lastUpdatedTerritoryData.Progress != tData.Progress || !tData.Color.CompareRGB(this.lastUpdatedTerritoryData.Color)) handler(sender, tData); this.lastUpdateEventTime = Time.realtimeSinceStartup; this.lastUpdatedTerritoryData = tData; } } }
protected override void onStart() { // Récupération de l'échelle de temps time = countrySimData.GetComponent <TimeScale>(); // Récupération des stats du virus virusStats = countrySimData.GetComponent <VirusStats>(); // Récupération des données du vaccin vaccine = countrySimData.GetComponent <Vaccine>(); // Récupération des finances finances = countrySimData.GetComponent <Finances>(); // Récupération de données de la frontière frontierPermeability = countrySimData.GetComponent <FrontierPermeability>(); // Récupération du stress de la population revolution = countrySimData.GetComponent <Revolution>(); // Récupération des données de la population countryPopData = countrySimData.GetComponent <TerritoryData>(); }
protected override void onStart() { // Récupération de l'échelle de temps time = countrySimData.GetComponent <TimeScale>(); // Récupération de données de la frontière frontierPermeability = countrySimData.GetComponent <FrontierPermeability>(); // Récupération du stress de la population revolution = countrySimData.GetComponent <Revolution>(); // Récupération des données de la population countryPopData = countrySimData.GetComponent <TerritoryData>(); // Récupération des données du télétravail remoteworking = countrySimData.GetComponent <Remoteworking>(); // Récupération des données du chômage partiel shortTimeWorking = countrySimData.GetComponent <ShortTimeWorking>(); // Récupération des données du soutien aux entreprises tax = countrySimData.GetComponent <Tax>(); // Récupération des données des masques masks = countrySimData.GetComponent <Masks>(); }
// Detatches the object and places it on the board. private void detachToBoard(Hand hand) { // EARLY OUT! // if (_snapper == null) { Debug.LogWarning(string.Format("Cannot use figurine, missing data. Snapper:{0}", _snapper)); return; } var gridPoint = _snapper.GridPoint; var snappedPosition = TerritoryData.GetCenter(gridPoint.X, gridPoint.Y); // Send the figurine down to its spawn position. var pos = transform.position; SetInteractable(false); StartCoroutine(dropFigurineToSpawn(pos, snappedPosition, hand)); }
protected override void onStart() { // Récupération de l'échelle de temps time = countrySimData.GetComponent <TimeScale>(); // Récupération des données de la population countryPopData = countrySimData.GetComponent <TerritoryData>(); // Create bars float yPos = -220f; for (int i = 0; i < countryPopData.popNumber.Length; i++) { buildBar("initPop", i, barPrefab, barsContainer.transform, countryPopData.popNumber[i], typeof(PopulationBar), new Color(0.34f, 0.47f, 0.81f), countryPopData.maxNumber, yPos); buildBar("infected", i, barPrefab, barsContainer.transform, countryPopData.popInfected[i], typeof(InfectedBar), new Color(0.86f, 0.39f, 0.22f), countryPopData.maxNumber, yPos); buildBar("treated", i, barPrefab, barsContainer.transform, countryPopData.popTreated[i], typeof(TreatedBar), new Color(0.36f, 0.81f, 0.34f), countryPopData.maxNumber, yPos); buildBar("death", i, barPrefab, barsContainer.transform, countryPopData.popDeath[i], typeof(DeathBar), new Color(0f, 0f, 0f), countryPopData.maxNumber, yPos); yPos += 5f; } }
void Awake() { if (instance == null) { instance = this; } else { Destroy(gameObject); } for (int r = 0; r < World.WORLD_SIZE; r++) { for (int c = 0; c < World.WORLD_SIZE; c++) { map[r, c] = new TerritoryData(); } } }
// Use to process your families. protected override void onProcess(int familiesUpdateCount) { time.newDay = false; time.timeElapsed += Time.deltaTime; // Calcul d'une nouvelle journée si le pas de simulation est dépassé if (time.timeElapsed > time.dayVelocity) { time.timeElapsed = time.timeElapsed - time.dayVelocity; foreach (GameObject territory in f_territories) { TerritoryData territoryData = territory.GetComponent <TerritoryData>(); ////////////////////////////////////// // GLISSEMENT JOURNALIER ////////////////////////////////////// // On passe donc au jour suivant for (int day = territoryData.numberOfInfectedPeoplePerDays.Length - 1; day > 0; day--) // Attention s'arrêter sur 1 pour pouvoir aller chercher le 0 { territoryData.numberOfInfectedPeoplePerDays[day] = territoryData.numberOfInfectedPeoplePerDays[day - 1]; } territoryData.numberOfInfectedPeoplePerDays[0] = 0; // Y compris pour chaque tranche d'age for (int age = 0; age < territoryData.numberOfInfectedPeoplePerAgesAndDays.Length; age++) { // Prise en compte du nombre de personnes guéries int treated = territoryData.numberOfInfectedPeoplePerAgesAndDays[age][territoryData.numberOfInfectedPeoplePerAgesAndDays[age].Length - 1]; territoryData.popTreated[age] += treated; territoryData.nbTreated += treated; // maintenant on peu passer au jour suivant for (int day = territoryData.numberOfInfectedPeoplePerAgesAndDays[age].Length - 1; day > 0; day--) // Attention s'arrêter sur 1 pour pouvoir aller chercher le 0 { territoryData.numberOfInfectedPeoplePerAgesAndDays[age][day] = territoryData.numberOfInfectedPeoplePerAgesAndDays[age][day - 1]; } territoryData.numberOfInfectedPeoplePerAgesAndDays[age][0] = 0; } } time.newDay = true; time.daysGone++; date = date.AddDays(1); } }
protected virtual void ThisTerritoryUpdated(MonoBehaviour sender, TerritoryData tData) { TerritoryUpdatedEventHandler handler = OnTerritoryUpdated; if (handler != null) { // Only fire this event every 10nth of a second if (Time.realtimeSinceStartup - this.lastUpdateEventTime > .1f) { // If something has actually updated and not set to the same value as before if (this.lastUpdatedTerritoryData.Progress != tData.Progress || !tData.Color.CompareRGB(this.lastUpdatedTerritoryData.Color)) { handler(sender, tData); } this.lastUpdateEventTime = Time.realtimeSinceStartup; this.lastUpdatedTerritoryData = tData; } } }
protected override void onStart() { // Récupération de l'échelle de temps time = countrySimData.GetComponent <TimeScale>(); // Récupération des données de la population countryPopData = countrySimData.GetComponent <TerritoryData>(); // Récupération de données de la frontière frontierPermeability = countrySimData.GetComponent <FrontierPermeability>(); // Récupération des finances finances = countrySimData.GetComponent <Finances>(); // Récupération de données du télétravail remoteworking = countrySimData.GetComponent <Remoteworking>(); // Récupération de données du chômage partiel shortTimeWorking = countrySimData.GetComponent <ShortTimeWorking>(); // Récupération de données des impôts de entreprises tax = countrySimData.GetComponent <Tax>(); // Récupération de données des lits de réanimation beds = countrySimData.GetComponent <Beds>(); finances.historySpent.Add(0); }
protected override void onStart() { TerritoryData countryData = time.GetComponent <TerritoryData>(); //Load game content from the file Dictionary <string, int[]> populationData = JsonConvert.DeserializeObject <Dictionary <string, int[]> >(rawContent.text); // Réinitialiser les données de la nation pour être sûr de les synchroniser avec les données accumulées des régions for (int age = 0; age < countryData.popNumber.Length; age++) { countryData.popNumber[age] = 0; } foreach (GameObject territory in f_territories) { TerritoryData territoryData = territory.GetComponent <TerritoryData>(); territoryData.popNumber = populationData[territoryData.TerritoryName]; int total = 0; int max = 0; for (int age = 0; age < territoryData.popNumber.Length; age++) { total += territoryData.popNumber[age]; max = Mathf.Max(max, territoryData.popNumber[age]); // accumulation au niveau national countryData.popNumber[age] += territoryData.popNumber[age]; } territoryData.nbPopulation = total; // Calcul de la puissance de 10 immediatement supérieure au maximum int multipleOfThousand = 0; int reste = 0; while (max - 1000 > 0) { max -= 1000; multipleOfThousand++; reste = max % 10; } multipleOfThousand++; territoryData.maxNumber = Mathf.Max(10000, multipleOfThousand * 1000); } territorySelected = countryData; territoryName.text = territorySelected.TerritoryName; }
// Triggered when the grid square changes that the figurine is over. // Updates the visual/haptic components of placement snapping. private void onFigurineGridSquareChanged() { if (_snapper != null) { bool isHighlightActive = _snapper.IsOverBoard && isPlaceableTerritory(_snapper.WorldPosition); SL.Get <GridSquareHighlight>().gameObject.SetActive(isHighlightActive); if (isHighlightActive) { var center = TerritoryData.GetCenter(_snapper.GridPoint.X, _snapper.GridPoint.Y); var snappedPos = new Vector3(center.x, 1f, center.z); SL.Get <GridSquareHighlight>().transform.position = snappedPos; // Trigger haptic pulse when the grid square changes. Hand hand = GetComponentInParent <Hand>(); if (hand && hand.controller != null) { hand.controller.TriggerHapticPulse(HapticGridSquareChange); } } } }
public void updateUI(TerritoryData territoryData, Beds territoryBeds) { setToggleUI(territoryData.closePrimarySchool_UIMaps, territoryData.closePrimarySchool, defaultMark); setToggleUI(territoryData.closeSecondarySchool_UIMaps, territoryData.closeSecondarySchool, defaultMark); setToggleUI(territoryData.closeHighSchool_UIMaps, territoryData.closeHighSchool, defaultMark); setToggleUI(territoryData.closeUniversity_UIMaps, territoryData.closeUniversity, defaultMark); setToggleUI(territoryData.callCivicism_UIMaps, territoryData.callCivicism, defaultMark); setToggleUI(territoryData.closeShop_UIMaps, territoryData.closeShop, defaultMark); setToggleUI(territoryData.certificateRequired_UIMaps, territoryData.certificateRequired, defaultMark); setToggleUI(territoryData.ageDependent_UIMaps, territoryData.ageDependent, defaultMark); territoryData.ageDependentMin_UIMaps.text = territoryData.ageDependentMin; territoryData.ageDependentMax_UIMaps.text = territoryData.ageDependentMax; if (territoryData.ageDependentMin != "" && territoryData.ageDependentMax != "") { territoryData.ageDependent_UIMaps.interactable = true; } else { territoryData.ageDependent_UIMaps.interactable = false; } setToggleUI(territoryBeds.beds_UIMaps, territoryBeds.boostBeds, defaultMark); SyncUISystem.needUpdate = true; }
public void UpdateR0UI(TMPro.TMP_Text textUI) { float R0 = 0; if (MapSystem.territorySelected.TerritoryName == countryPopData.TerritoryName) { // Calcul du R0 national à partir des R0 territoriaux float r0Cumul_national = 0; foreach (GameObject territory in f_territories) { TerritoryData territoryData = territory.GetComponent <TerritoryData>(); // aggréger la valeur du R0 pondéré par le nombre de personnes vivante dans ce territoire r0Cumul_national += ComputeR0(territoryData) * (territoryData.nbPopulation - territoryData.nbDeath) / (countryPopData.nbPopulation - countryPopData.nbDeath); } // calcul de la moyenne des R0 au niveau national R0 = r0Cumul_national; } else { R0 = ComputeR0(MapSystem.territorySelected); } textUI.text = "R0 : " + R0.ToString("N2", CultureInfo.CreateSpecificCulture("fr-FR")); }
void TerritoryExit(ExposedTrigger sender, ExposedTrigger.TriggerActivityEventArgs e) { Player player = e.gameObject.GetComponent<Player>(); if(player != null) { // Remove the element List<Player> playerList; if (!this.playersCapturing.TryGetValue(player.PlayerTeam, out playerList)) this.playersCapturing.Add(player.PlayerTeam, playerList = new List<Player>()); playerList.Remove(player); this.CheckIfPlayerIsCapturing(); // Something changed so maybe someone is capturing } // Fire our own event from this script TerritoryData tData = new TerritoryData(); tData.Progress = this.CaptureProgress; tData.Color = new ColorData(this.LockedCaptureState ? this.LockedCaptureState.ThisTeamToColor() : Player.TeamToColor(Player.Team.None)).ToDictionary(); tData.LockedColor = new ColorData(this.LockedCaptureState ? this.LockedCaptureState.ThisTeamToColor() : Player.TeamToColor(Player.Team.None)).ToDictionary(); tData.TempColor = new ColorData(this.tempCaptureState ? this.tempCaptureState.ThisTeamToColor() : Player.TeamToColor(Player.Team.None)).ToDictionary(); this.OnTerritoryExited(this, new TerritoryActivityEventArgs(player, tData)); }
public TerritoryActivityEventArgs(Player player, TerritoryData tData) { this.player = player; this.TerritoryData = tData; }
void HandleCapturing() { // If there is a player capturing if(this.playerCapturing) { if(this.tempCaptureState == this.playerCapturing) { // Capture point this.CaptureProgress += Time.deltaTime/this.TimeToCapture; // Only lock the capture state once we reach the progress of 1 if(this.LockedCaptureState != this.tempCaptureState && this.CaptureProgress >= 1f) { // Captured point this.LockedCaptureState = this.playerCapturing; // Fire the event TerritoryData tDataLocked = new TerritoryData(); tDataLocked.Progress = this.CaptureProgress; tDataLocked.Color = new ColorData(this.LockedCaptureState.ThisTeamToColor()).ToDictionary(); tDataLocked.LockedColor = new ColorData(this.LockedCaptureState.ThisTeamToColor()).ToDictionary(); tDataLocked.TempColor = new ColorData(this.LockedCaptureState.ThisTeamToColor()).ToDictionary(); this.OnTerritoryCaptured(this, new TerritoryActivityEventArgs(this.LockedCaptureState, tDataLocked)); } } else { // Uncapture the point // we trying to steal this territory this.CaptureProgress -= Time.deltaTime/this.TimeToCapture; // Only unlock the capture state once we reach the progress of 0 if(this.CaptureProgress <= 0f) { Debug.Log("captureProgress <= 0 ~~ " + (this.LockedCaptureState ? this.LockedCaptureState.PersonalColor.ToString() : "") + " : " + (this.tempCaptureState ? this.tempCaptureState.PersonalColor.ToString() : "")); if(this.LockedCaptureState) { // Make sure to only unlock the point once if(this.LockedCaptureState != this.playerCapturing) { // Fire the event Debug.Log("OnTerritoryLost"); TerritoryData tDataUnlocked = new TerritoryData(); tDataUnlocked.Progress = this.CaptureProgress; tDataUnlocked.Color = new ColorData(Player.TeamToColor(Player.Team.None)).ToDictionary(); tDataUnlocked.LockedColor = new ColorData(Player.TeamToColor(Player.Team.None)).ToDictionary(); tDataUnlocked.TempColor = new ColorData(this.playerCapturing.ThisTeamToColor()).ToDictionary(); this.OnTerritoryLost(this, new TerritoryActivityEventArgs(this.LockedCaptureState, tDataUnlocked)); } } // Uncapture point this.LockedCaptureState = null; // Now that we uncaptured the point set the temp capture state to the capturing player this.tempCaptureState = this.playerCapturing; } } // Fire Event TerritoryData tData = new TerritoryData(); tData.Progress = this.CaptureProgress; tData.Color = new ColorData(this.LockedCaptureState ? this.LockedCaptureState.ThisTeamToColor() : Player.TeamToColor(Player.Team.None)).ToDictionary(); tData.LockedColor = new ColorData(Player.TeamToColor(Player.Team.None)).ToDictionary(); tData.TempColor = new ColorData(this.playerCapturing.ThisTeamToColor()).ToDictionary(); this.ThisTerritoryUpdated(this, tData); } else { // If the hill isn't contested then auto-progress if(!this.territoryContested) { // If someone is not capturing and it is captured by some team, auto progress up if(this.LockedCaptureState && this.LockedCaptureState.PlayerTeam != Player.Team.None) { this.CaptureProgress += Time.deltaTime/this.TimeToCapture; // Fire Event TerritoryData tData = new TerritoryData(); tData.Progress = this.CaptureProgress; tData.Color = new ColorData(this.LockedCaptureState.ThisTeamToColor()).ToDictionary(); tData.LockedColor = new ColorData(this.LockedCaptureState.ThisTeamToColor()).ToDictionary(); tData.TempColor = new ColorData(Player.TeamToColor(Player.Team.None)).ToDictionary(); this.ThisTerritoryUpdated(this, tData); } // Otherwise we should auto progress down as the team trying didn't stay long enough else { this.CaptureProgress -= Time.deltaTime/this.TimeToCapture; // just clean up in case anything happened if(this.CaptureProgress <= 0f) { // Uncapture point this.LockedCaptureState = null; // Now that we uncaptured the point set the temp capture state to the capturing player this.tempCaptureState = this.playerCapturing; } // Fire Event TerritoryData tData = new TerritoryData(); tData.Progress = this.CaptureProgress; tData.Color = new ColorData(Player.TeamToColor(Player.Team.None)).ToDictionary(); tData.LockedColor = new ColorData(Player.TeamToColor(Player.Team.None)).ToDictionary(); tData.TempColor = new ColorData(Player.TeamToColor(Player.Team.None)).ToDictionary(); this.ThisTerritoryUpdated(this, tData); } } } //Debug.Log("Player: " + (this.playerCapturing ? this.playerCapturing.PlayerTeam.ToString() : "None") + (this.playerCapturing ? this.playerCapturing.PersonalColor.ToString() : "") + " - Contested?: " + this.territoryContested +" - Progress: " + this.CaptureProgress + " - TempState: " + (this.tempCaptureState ? this.tempCaptureState.PlayerTeam.ToString() : "None") + (this.tempCaptureState ? this.tempCaptureState.PersonalColor.ToString() : "") + " - LockedState: " + (this.LockedCaptureState ? this.LockedCaptureState.PlayerTeam.ToString() : "None") + (this.LockedCaptureState ? this.LockedCaptureState.PersonalColor.ToString() : "")); }