public override void Copy(AbstractObject source) { WildAnimal ani = source as WildAnimal; _currentChance = ani._currentChance; base.Copy(source); }
public void InitializeValues(WildAnimal wa) { // False since we're starting a new bait cycle wa.recentlyBaited = false; if (!CheckIfEnoughBait(wa)) { wa.animalState = wa.animalStates["wander"]; return; } // Check which percentage the player is within the action radius (from wander to comfort) // Set the BaitMoveInterval to either 20.25, 27 or 40.5 based on distance correlating to how many attempts it will take to fully tame the animal { // action layer min = comfortRadius, max = actionRadius float percentageWithinActionLayer = MathFunctions.ConvertNumberRanges(wa.playerDistance, wa.actionRadius, wa.comfortRadius, 100, 0); // out of 100% if (percentageWithinActionLayer > 70) { wa.baitMoveInterval = 20.25f; } else if (percentageWithinActionLayer > 40) { wa.baitMoveInterval = 27.0f; } else if (percentageWithinActionLayer > 0) { wa.baitMoveInterval = 40.5f; } } // Animal's current position is now the starting point animalStartPosition = wa.transform.position; }
public void MoveTargetPositionCheck(WildAnimal wa) { wa.wanderChangeTimer -= Time.deltaTime; if (wa.wanderChangeTimer <= 0) { wa.MoveTargetPosition(); } }
public void Behavior(WildAnimal wa) { if (!wa.moveToMarker) { return; } if (wa.playerDistance < wa.wanderRadius) { // Make sure path is valid GraphNode n1, n2; n1 = AstarPath.active.GetNearest(wa.transform.position).node; n2 = AstarPath.active.GetNearest(wa.moveToMarker.transform.position).node; if (!PathUtilities.IsPathPossible(n1, n2)) { wa.MoveTargetPosition(); return; } } if (Vector3.Distance(wa.transform.position, wa.moveToMarker.position) < wa.stopDistance * 2) { wa.targetReached = true; } else { wa.targetReached = false; } if (wa.targetReached) { MoveTargetPositionCheck(wa); } // If moveToMarker is outside of working radius, ignore rest of movement code if (Vector3.Distance(wa.moveToMarker.position, wa.wanderMarker.position) > wa.wanderRadius) { //MoveTargetPosition (); wa.moveToMarker.position = wa.wanderMarker.position; } if (Vector3.Angle(PlayerController.instance.transform.position - wa.transform.position, wa.moveToMarker.position - wa.transform.position) < 90) { Vector3 dirToPlayer = (wa.moveToMarker.position - PlayerController.instance.transform.position).normalized; wa.moveToMarker.position += dirToPlayer * wa.maxSpeed * Time.deltaTime; } if (wa.playerDistance < wa.wanderRadius) { if (AstarPath.active.GetNearest(wa.moveToMarker.transform.position, NNConstraint.Default).node != null) { wa.moveToMarker.transform.position = (Vector3)AstarPath.active.GetNearest(wa.moveToMarker.transform.position, NNConstraint.Default).node.position; } } }
private void InsertData(ITestDataContext db) { var eye = new Eye { Id = 1, Xy = "Hallo" }; var dog = new Dog { Id = 1, Discriminator = "Dog", EyeId = 1, Name = "FirstDog", DogName = new Name { First = "a", Second = "b" }, AnimalType = AnimalType.Big, AnimalType2 = AnimalType2.Big }; var wildAnimal = new WildAnimal { Id = 2, Discriminator = "WildAnimal", Name = "WildAnimal", AnimalType = AnimalType.Big, AnimalType2 = AnimalType2.Big }; var test = new Test { Id = 1, TestAnimalId = null }; var test2 = new Test { Id = 2, TestAnimalId = 1 }; using (new DisableLogging()) { db.CreateLocalTable <Animal>(); db.CreateLocalTable <Eye>(); db.CreateLocalTable <Test>(); db.Insert(eye); db.Insert(dog); db.Insert(wildAnimal); db.Insert(test); db.Insert(test2); } }
public void ReactionToPlayer(WildAnimal wa) // second update { if (wa.annoyedTimeoutCounter < 5) { wa.annoyedTimeoutCounter += Time.deltaTime; } wa.GetComponent <Renderer> ().material.color = Color.white; wa.annoyedTimeoutCounter = wa.annoyedTimeoutCounter < -5 ? -5 : wa.annoyedTimeoutCounter; }
public void Behavior(WildAnimal wa) { // ... // Move away until far enough away from the player while staying within wander radius at half speed. // If moving away requires leaving wander radius, place marker somewhere else within wanderRadius and double normal speed. // We cover the effects of becoming annoyed in DetectStateChange() // Get where the player is and avoid it wa.CheckPlayerFrontPosition(); // If we hit the bounds of the wander area, perform new code (shown below in BoundaryOperation) if (wa.reachedBoundary) { return; } Vector3 directionFromPlayer = wa.transform.position - PlayerController.instance.transform.position; directionFromPlayer.y = 0; directionFromPlayer = directionFromPlayer.normalized; Vector3 newMarkerPosition = wa.transform.position + (directionFromPlayer * wa.comfortRadius); wa.moveToMarker.position = newMarkerPosition; // When ANIMAL leaves wander radius if (Vector3.Distance(newMarkerPosition, wa.wanderMarker.position) >= wa.wanderRadius) // animal needs a trigger event for when it leaves it's own wander radius ? { Vector3 newDirection = wa.DetermineReflectionDirection(30.0f); newMarkerPosition = wa.transform.position + (newDirection * wa.comfortRadius); wa.StartCoroutine(wa.BoundaryOperation(1.0f, newDirection)); return; } //if (wa.annoyedTimeoutCounter > 0) // wa.moveToMarker.transform.position = newMarkerPosition; //else //{ // if (wa.annoyedRandomShiftTimer < 0) // { // wa.MoveTargetWildPosition (); // wa.annoyedRandomShiftTimer = wa.annoyedRandomShiftTimerDefault; // wa.annoyedTimeoutCounter = wa.annoyedTimeoutCounterDefault; // } // wa.annoyedRandomShiftTimer -= Time.deltaTime; // // wa.moveToMarker.transform.position = (Vector3)AstarPath.active.GetNearest (wa.moveToMarker.transform.position, NNConstraint.Default).node.position; //} }
// Move at intervals - used instead of normal AI behavior when too far from the player public void Behavior(WildAnimal wa) { actionCounter -= Time.deltaTime; if (actionCounter < 0) { actionCounter = 5.0f; wa.MoveTargetPosition(); } Vector3 moveDirection = wa.moveToMarker.position - wa.transform.position; moveDirection = moveDirection.normalized; moveDirection.y = 0; float simpleSpeed = 4.0f; wa.CController.SimpleMove(moveDirection * simpleSpeed); }
/// <summary> /// Find random animal on the hunting. /// </summary> /// <param name="count">how many animals was found</param> /// <returns></returns> public static WildAnimal FindSomeone(out int count) { float val = UnityEngine.Random.value * (float)_sAllWildAnimal.Count; int position = (int)(val); WildAnimal ani = _sAllWildAnimal[position]; val -= position; val *= ani.m_maxInSquadre; //no one was found if (val > ani.m_count) { count = 0; return(ani); } count = (int)(((float)ani.m_maxInSquadre - (float)ani.m_minInSquadre) * UnityEngine.Random.value) + ani.m_minInSquadre; return(ani.m_count < count?FindSomeone(out count) : ani); }
/// <summary> /// Parse all recipe /// </summary> public static void ParseDependency() { for (int it = 0; it < m_sEverything.Count; it++) { var rep = m_sUnparsed[it] as ExcelLoading.AbstractItem; var mat = m_sEverything[it] as GameAbstractItem; WildAnimal wild = m_sEverything[it] as WildAnimal; if (wild != null) { wild.ParseDependency(m_sUnparsed[it]); } if (mat == null) { continue; } var prod = rep.produce_per_person; try { if (rep.dependency.Length > 2) { mat.m_dependencyCount = ParseDependencyCounts(rep.dependency); } //prod could have two different formats: single float or dependencyCount format if (prod[0] >= '0' && prod[0] <= '9') { mat.m_producePerPerson = new DependencyCount[1]; mat.m_producePerPerson[0] = new DependencyCount(); mat.m_producePerPerson[0].m_dependency.Add(mat); mat.m_producePerPerson[0].m_value.Add(FloatParse(prod, ".")); } else { mat.m_producePerPerson = ParseDependencyCounts(prod); } } catch (Exception ex) //error in the excel file. { Debug.Log("Object parsing error:" + mat.m_name + " " + ex.Message); } } }
/// <summary> /// loading data from xml files /// </summary> public void Loading() { //order is important! from parents to children, science the last one EffectTypeHolder.Load("effect_map"); MineralResource.Load("mineralResource_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Resource.Load("resource_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); GameMaterial.Load("materials_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Items.Load("items_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Buildings.Load("buildings_Map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Army.Load("army_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Process.Load("process_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); Science.Load("science_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); DomesticAnimal.Load("domesticAnimal_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); WildAnimal.Load("wildAnimal_map"); //Debug.Log("all items amount:" + GameAbstractItem.ItemsCount()); LearningTip.Load("AllTips_Map"); GameAbstractItem.ParseDependency(); Population ppl = new Population { m_people = GetComponent <People>(), m_isItOpen = 1 }; AbstractObject.m_sEverything.Add(ppl); Localization.GetLocalization().FirstLoad(); Localization.GetLocalization().ChangeLanguage(Localization.GetLocalization().m_currentLanguage); AbstractObject.ClearUnparsed(); Debug.Log("loading finished"); }
public void ReactionToPlayer(WildAnimal wa) { if (wa.playerRadiusPosition == 3) // within comfort layer { // If the player isn't holding down Offer Bait, become annoyed if (!PlayerController.instance.CheckPlayerState("offerbait")) { wa.animalState = wa.animalStates["annoyed"]; wa.EndBaitProcess(); } } if (wa.playerRadiusPosition == 1) // within wander layer (no action, comfort) { // lose interest if player exits action layer if (!PlayerController.instance.CheckPlayerState("offerbait")) { wa.animalState = wa.animalStates["wander"]; wa.EndBaitProcess(); } } }
public void ReactionToPlayer(WildAnimal wa) { if (wa.playerRadiusPosition == 3) // within comfort layer { wa.GetComponent <Renderer> ().material.color = new Color(1.0f, 0.45f, 0.0f, 1.0f); // orange? wa.animalState = wa.animalStates["annoyed"]; wa.annoyedTimeoutCounter -= Time.deltaTime; wa.CheckForBaitTotalLockout(); // If the player isn't holding down Offer Bait, become annoyed if (!PlayerController.instance.CheckPlayerState("offerbait")) { wa.animalState = wa.animalStates["annoyed"]; wa.EndBaitProcess(); } } else { if (wa.annoyedTimeoutCounter < 5) { wa.annoyedTimeoutCounter += Time.deltaTime; } } if (wa.playerRadiusPosition == 2) // within action layer (no comfort) { wa.GetComponent <Renderer> ().material.color = Color.white; wa.annoyedTimeoutCounter = wa.annoyedTimeoutCounter < -5 ? -5 : wa.annoyedTimeoutCounter; } if (wa.playerRadiusPosition == 1) // within wander layer (no action, comfort) { wa.GetComponent <Renderer> ().material.color = Color.blue; } }
// We make sure the player has proper bait equipped for the animal, AND that the player has ENOUGH of said bait public bool CheckIfEnoughBait(WildAnimal wa) { if (!Inventory.instance.CheckBaitAmount(Inventory.instance.currentBait.ToString(), 1)) { //print ("Not enough bait in bag."); return(false); } bool allowed = false; for (int i = 0; i < wa.allowedBait.Length; i++) { if (Inventory.instance.currentBait.ToString().ToLower() == wa.allowedBait [i].ToString().ToLower()) { allowed = true; } //print ("Bait Inv.: " + Inventory.instance.currentBait.ToString () + " : Allowed type: " + allowedBait [i]); } //print ("Allowed: " + allowed); return(allowed); }
private void displayWildAnimal() { DataLoaded = false; byte[] wildBytes = new byte[72]; Array.Copy(MainForm.SaveData, wildOffset + 72 * wildTypeComboBox.SelectedIndex, wildBytes, 0, 72); currentWildAnimal = new WildAnimal(wildBytes); wildFriendshipNumericUpDown.Value = currentWildAnimal.Friendship; // Editing unappeared wild animal is disabled for now. if (currentWildAnimal.ID == 0xFF) { wildFriendshipNumericUpDown.Enabled = false; canEditWild = false; } else { wildFriendshipNumericUpDown.Enabled = true; canEditWild = true; } DataLoaded = true; }
/// <summary> /// parsing excel data into current format /// </summary> /// <param name="mat">target</param> /// <param name="rep">source</param> /// <returns> parsed item </returns> /// <returns></returns> public static new AbstractObject Parse(AbstractObject mat, ExcelLoading.AbstractObject rep) { WildAnimal ani = mat as WildAnimal; ExcelLoading.WildAnimalItem aniRep = rep as ExcelLoading.WildAnimalItem; if (ani != null && aniRep != null) { ani.m_attack = aniRep.attack; ani.m_protection = aniRep.protection; ani.m_speed = aniRep.speed; ani.m_scary = aniRep.scary; ani.m_minInSquadre = decimal.ToInt32(aniRep.minimal_in_squadre); ani.m_maxInSquadre = decimal.ToInt32(aniRep.maximum_in_squadre); ani.m_chanceToTame = aniRep.chance_to_tame; _sAllWildAnimal.Add(ani); } else { Debug.Log("WildAnimal.Parse: critical parse error"); } return(AbstractAnimal.Parse(mat, rep)); }
public void Behavior(WildAnimal wa) { }
public void CheckPlayerPosition(WildAnimal wa) { }
public void CheckPlayerPosition(WildAnimal wa) { // Purposefully left blank }
public void ReactionToPlayer(WildAnimal wa) { // Purposefully left blank }
public void Action(WildAnimal wa) { // Purposefully left blank }
public float comfortRadiusSizeChangeAmount; // ... /\ /\ /\ public void Behavior(WildAnimal wa) { if (!PlayerController.instance.CheckPlayerState("offerbait") || wa.waitForPlayerNextAction) { return; } // Check how close the animal is to it's current destination, then mark that as a bool float animalDistanceToMovePoint = Vector3.Distance(wa.moveToMarker.transform.position, MathFunctions.ShiftToCenterPoint(animalStartPosition, wa.baitHolderTarget.position, wa.percentageDistance)); if (animalDistanceToMovePoint > 2) { waitForAnimalMove = true; } else { waitForAnimalMove = false; } wa.moveToMarker.transform.position = MathFunctions.ShiftToCenterPoint(animalStartPosition, wa.baitHolderTarget.position, wa.percentageDistance); if (waitForAnimalMove) // let animal reach destination first { return; } // While being baited, count down toward a final action if (wa.baitTimeoutCounter > 0) { wa.baitTimeoutCounter -= Time.deltaTime; wa.GetComponent <Renderer> ().material.color = Color.red; } else { // Increase pDist which determines where the animal rests in relation to the player wa.percentageDistance += wa.baitMoveInterval; // Shrink comfort/action radius' so the player is forced to move closer - shrinks based on original distances float shrinkAmount = Vector3.Distance(PlayerController.instance.transform.position, wa.transform.position); wa.actionRadius = shrinkAmount + 1; wa.comfortRadius = shrinkAmount / 2 + 1; // Reset timer wa.baitTimeoutCounter = wa.baitTimeoutCounterDefault; // Pause animal actions until the player reinitiates the bait process wa.waitForPlayerNextAction = true; wa.GetComponent <Renderer> ().material.color = new Color(1.0f, 0.92f, 0.016f, 1.0f); //yellow } float animalDistance = Vector3.Distance(PlayerController.instance.transform.position, wa.transform.position); if (wa.percentageDistance >= 80 && animalDistance < 3) { // Check for success / failure when taking bait here float chance = Random.Range(0, 100); if (chance < wa.chanceForTotalLockout) { Debug.Log("TOTAL LOCKOUT " + chance + " < " + wa.chanceForTotalLockout + " = true"); GameObject.Destroy(wa.transform.gameObject); Inventory.instance.RemoveBait(Inventory.instance.currentBait.ToString(), 1); } else { chance = Random.Range(0, 100); // re-roll to make values < totalLockout valid if (chance < chanceForBaitSuccess + (wa.animalAffinity * 10) + wa.baitMoveInterval) // up to a max of 100% currently (50% +0, +10, +20, +30, +40 -> 100% with +50) + baitMoveInterval to make better plays more rewarded (20, 27, 40) { // Here is where we lock the animal from all action, play the motion of it running to the player //... Debug.Log("SUCCESS! Here is where we display the menu for the player to decide on an action to take."); GameObject.Destroy(wa.transform.gameObject); Inventory.instance.RemoveBait(Inventory.instance.currentBait.ToString(), 1); } else { // Here is where we lock the animal from all action, play the motion of it running to the player, nabbing the bait and running away //... wa.recentlyBaited = true; Debug.Log("Unsuccessful (" + wa.animalAffinity + " : " + (chanceForBaitSuccess + (wa.animalAffinity * 10) + wa.baitMoveInterval) + ") Animal took bait and likes the player a bit more now."); wa.animalAffinity += wa.animalAffinity > 5 ? 0 : 1; // 5 max? Inventory.instance.RemoveBait(Inventory.instance.currentBait.ToString(), 1); } } // end bait, restore values here wa.EndBaitProcess(); } // Rules: // Notice and walk toward player a bit before stopping - distance based on player's start distance // Shrink comfort zone allowing the animal to come closer without fear // Check if the comfort zone is smaller than a certain radius, if so we animate the animal to come to the player's hand // If the player at any point in time stops holding the Bait button, animal resets, but not the ChanceForTotalLockout or comfort radius, which increases when comfort zone is entered // Entering comfort layer resets comfort layer, checks for total lockout, and if total lockout fails, increases the chance for total lockout if bait was offered recently }
public void InitializeValues(WildAnimal wa) { // Purposefully left blank }
public void Action(WildAnimal wa) { }
public void CheckPlayerState(WildAnimal wa) { // Purposefully left blank }
public void InitializeValues(WildAnimal wa) { }
public void ReactionToPlayer(WildAnimal wa) { wa.annoyedTimeoutCounter -= Time.deltaTime; }
public void CheckPlayerState(WildAnimal wa) { }
void AnimalHunting(long workers) { int count = 0; WildAnimal ani = WildAnimal.FindSomeone(out count); int killedAnimals = 0; // prepare float speed = 1; float attackDistance = 1; float attack = 1f; float protection = 0; float distance = 10; //calc attributes foreach (var tool in m_tools) { foreach (var effectPair in tool.m_toolLink.m_effects) { var effect = effectPair.Value; switch (effect.m_name) { case "hunt": attack += (1 + tool.m_value); break; case "protection": protection += tool.m_value; break; case "attack_distance": if (effect.m_value > attackDistance) { attackDistance = effect.m_value; } break; } } } if (attackDistance > distance) { distance = attackDistance; } bool scared = false; float aniHealth = ani.m_protection * count; float squadreHealth = workers * 10; long hunters = workers; // fight! while (killedAnimals < count && !(scared && distance > attackDistance && ani.m_speed > speed) && squadreHealth > 0) { //attack animals if (distance <= attackDistance) { aniHealth -= attack * workers; killedAnimals = count - (int)((aniHealth / ani.m_protection) + (float.Equals(aniHealth % ani.m_protection, 0) ? 0f : 1f)); } // animals attack if (distance <= 1) { float aniAttack = ani.m_attack * (count - killedAnimals) - protection * workers; if (aniAttack > 0) { squadreHealth -= aniAttack; workers = (int)(squadreHealth / 10f + (squadreHealth % 10f > 0f ? 1f : 0f)); } } scared = (count - killedAnimals) < ani.m_scary; distance += -speed + (scared ? 1 : -1) * ani.m_speed; if (distance < 0) { distance = 0; } } //how many hunters was killed long killedWorkers = hunters - workers; m_workers -= killedWorkers; Storage.m_storage.m_people.PeopleNumber -= killedWorkers; ani.m_count -= killedAnimals; for (int it = 0; it < ani.m_butcheringPerPerson.Length; it++) { var dep = ani.m_butcheringPerPerson[it]; { for (int i = 0; i < dep.m_dependency.Count; i++) { dep.m_dependency[i].m_count += dep.m_value[i] * killedAnimals; GameMaterial mat = dep.m_dependency[i] as GameMaterial; if (mat != null) { float maxCount = ((float)mat.StorageSize / mat.m_size); if (dep.m_dependency[i].m_count > maxCount) { dep.m_dependency[i].m_count = maxCount; } } } } } }