public void OnCollisionEnter(Collision collision) { GameObject otherGO = collision.collider.gameObject; if (otherGO.tag == "Sweets") { Debug.Log("Hit"); Rigidbody rigidBody = GetComponent <Rigidbody>(); rigidBody.isKinematic = false; rigidBody.useGravity = true; Rigidbody otherGORigidBody = otherGO.GetComponent <Rigidbody>(); rigidBody.velocity = otherGORigidBody.velocity; rigidBody.angularVelocity = otherGORigidBody.angularVelocity; Destroy(otherGORigidBody); if (this.GetComponent <Infection>() != null) { Infection infection = this.GetComponent <Infection>(); if (infection._isFullyInfected == false) { gameControl.DecreaseHealth(); } } else { gameControl.DecreaseHealth(); } Destroy(otherGO); skull.RemoveTooth(this.gameObject); } }
public GridNode(char start, int x, int y) { X = x; Y = y; Nodes[$"{x},{y}"] = this; Infected = start == '#' ? Infection.Infected : Infection.Clean; }
public int Start() { bool fightTied = false; while (ImmuneSystem.Any(g => !g.Removed) && Infection.Any(g => !g.Removed) && !fightTied) { var unitCountBeforeRound = GroupsInTargetSelectionOrder.Sum(g => g.Units); var alreadySelected = new HashSet <int>(); foreach (var group in GroupsInTargetSelectionOrder) { var target = group.SelectTarget(alreadySelected); if (target != null) { alreadySelected.Add(target.Id); } } foreach (var group in GroupsInAttackingOrder) { group.AttackTarget(); } fightTied = unitCountBeforeRound == GroupsInTargetSelectionOrder.Sum(g => g.Units); } var immuneSystemPoints = ImmuneSystem.Where(g => g.Units >= 0).Sum(g => g.Units); var infectionPoints = Infection.Where(g => g.Units >= 0).Sum(g => g.Units); return(Math.Max(immuneSystemPoints, infectionPoints)); }
public Entity(Transform transformTemp, bool infected, float recoveryRate, float transferChance, float moveSpeed) { /* * The constructor for entity where five parameters are defined. * Creates an ID, sets the object's transform (the unity sprite which it is associated to) * and initialises its sprite, movement class (compositionally aggregated) and * infection class (also compositionally aggregated). */ transform = transformTemp; //Creates a unique ID for each entity ID = tempID; tempID++; //Sets up movement composite object movement = transform.gameObject.GetComponent <Movement> (); movement.Initialise(this, moveSpeed); //Sets up infection composite object infection = transform.gameObject.GetComponent <Infection> (); infection.Initialise(transferChance, recoveryRate, infected); infection.ID = ID; sprite = transform.gameObject.GetComponent <SpriteRenderer> (); }
// decreases infection count of colliding player by 1 void GiveCure() { Infection infection = _player.GetComponent <Infection>(); infection.DecrementInfectionNumber(); // TODO: decrement needs to set infectedFlag to false when 0, increment needs to reset infectedFlag to true }
/// <summary> /// /// </summary> public void InfectTooth() { if (teeth.Count > 0) { for (int attemptedToothCount = 0; attemptedToothCount < teeth.Count; attemptedToothCount++) { int index = (int)Random.Range(0, teeth.Count); GameObject selectedTooth = teeth[index]; if (selectedTooth.GetComponent <Infection>() == null) { Infection newInfection = selectedTooth.AddComponent <Infection>(); newInfection.infectedColour = infectionColour; _infectToothCount++; break; } else { continue; } } } if (_infectToothCount == teeth.Count) { _allTeethInfected = true; } }
// Update is called once per frame void Update() { if (player == null) { SceneManager.LoadScene(LoseSceneName, LoadSceneMode.Single); } else if (playerCollecter.CurrentCollected == TotalCollectedItems) { SceneManager.LoadScene(WinSceneName, LoadSceneMode.Single); } UpdateText(string.Format(scoreFormat, playerCollecter.CurrentCollected, TotalCollectedItems)); if (playerInfection == null) { playerInfection = player.GetComponent <Infection>(); } else { UpdateInfectionMarkers(); } if (!visionEnable) { visionEnable = playerCollecter.VisionEnable; if (visionEnable) { npcControler.TurnOnInfectionVision(); } } }
static Infection start(Field field, Population infections) { List <Infection> previous = null; Dictionary <Infection, Result> top = new Dictionary <Infection, Result>(); while (true) { Dictionary <Infection, Result> res; if (previous == null) { res = startRound(field, infections, top); } else { Population newInfections = new Population(infections.Count, previous); res = startRound(field, newInfections, top); } KeyValuePair <Infection, Result> maxResult = res.OrderByDescending((kvp) => kvp.Value).First(); if (maxResult.Value.steps >= STEP_LIMIT) { Infection found = maxResult.Key; return(found); } previous = res // .Where((kvp) => kvp.Value >= previousMax) .Select((kvp) => kvp.Key).ToList(); } }
public void CheckForInfection(Infection infector) { if (!infection && Random.value > infector.infectionChance) { BecomeInfected(); } }
public static void Cure(this Player player, ItemType item = ItemType.None) { if (InfectedPlayers.ContainsKey(player)) { Infection infection = InfectedPlayers[player]; infection.Cure(item); } }
public static void RemoveInfection(Infection inf) { infections.Remove(inf); if (infections.Count == 0) { //win! SceneManager.LoadScene(5); } }
private void initInfections() { Random rand = new Random(); Infection inf1 = new Infection() { Size = 5, StoreSize = 2, Aggression = 12, SpreadSpeed = 3, SpreadDistance = 1, SpreadArea = 1, StrengthPref = 0.75f }; InfectionSpeciman s1 = new InfectionSpeciman(inf1); this.infections.Add(inf1, Color.Red); Victim v = field.Data[rand.Next(0, SIZE_X), rand.Next(0, SIZE_Y)]; //v.Health = Field.MAX_HEALTH; v.Infect(s1); Infection inf2 = new Infection() { Size = 1, StoreSize = 4, Aggression = 9, SpreadSpeed = 5, SpreadDistance = 2, SpreadArea = 2, StrengthPref = 0.75f }; this.infections.Add(inf2, Color.Green); InfectionSpeciman s2 = new InfectionSpeciman(inf2); field.Data[rand.Next(0, SIZE_X), rand.Next(0, SIZE_Y)].Infect(s2); field.FieldProgressEvent += field_FieldProgressEvent; Infection inf3 = new Infection() { Size = 1, StoreSize = 2, Aggression = 5, SpreadSpeed = 5, SpreadDistance = 1, SpreadArea = 1, StrengthPref = 0.75f }; this.infections.Add(inf3, Color.DarkOrange); InfectionSpeciman s3 = new InfectionSpeciman(inf3); field.Data[rand.Next(0, SIZE_X), rand.Next(0, SIZE_Y)].Infect(s3); }
// increments infection count of all players by 1 void GiveInfectionToAll() { GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject player in players) { Infection infection = player.GetComponent <Infection>(); infection.IncrementInfectionNumber(); } }
void Start() { agent = GetComponent <UnityEngine.AI.NavMeshAgent>(); infections = transform.GetComponent <Infection>(); alive = true; didFire = false; agent.autoBraking = false; agent.speed = patrolSpeed; }
public void InfectionTest() { Console.WriteLine("Testing Infection..."); Infection i = new Infection(); //FP1 and UP Person p = new Person(Person.Mask.Protection.FP1); //switch to DOWN p.switchMaskState(); //Infection probability would be to 100% Assert.True(i.apply(p)); }
void InfectOther(GameObject other) { Infection otherInfection = other.gameObject.GetComponent <Infection>(); if (canInfect && otherInfection != null && other.GetType() != typeof(SphereCollider) && !(currentState == InfectionType.NotInfected || currentState == InfectionType.PotentialInfection) && otherInfection.currentState == InfectionType.NotInfected) { otherInfection.currentState = InfectionType.PotentialInfection; manager.notInfected--; otherInfection.CheckInfection(); } }
private static Infection IncInfection(Infection currentLevel) { if (currentLevel != Infection.flagged) { currentLevel++; } else { currentLevel = Infection.clean; } return(currentLevel); }
static void Main(string[] args) { Field field = null; string infectionsFile = null; bool showHelp = false; OptionSet p = new OptionSet() .Add("h|?|help", (v) => { showHelp = v != null; }) .Add("f|field=", (v) => { if (v != null) { field = new Field(v); } }) .Add("i|infections=", (v) => { if (v != null) { infectionsFile = v; } }) .Add("nolog", (v) => { Logger.Instance.Disabled = true; }); List <string> extra = p.Parse(args); if (showHelp) { Console.WriteLine(p.ToString()); } else { if (field == null) { field = new Field(SIZE_X, SIZE_Y, MIN_HEALTH, MAX_HEALTH); } Population infections = (infectionsFile == null) ? new Population(POPULATION_SIZE) : new Population(POPULATION_SIZE, infectionsFile); Infection res = start(field, infections); Console.WriteLine("Winner: {0}", res.ToString()); Console.ReadLine(); } }
void Tick() { if (Infection != null) { timeSinceInfection++; if (!permanentlyInfected && Random.value < 0.01F / GetTraitValue("virus_resistance")) { immunity.Add(Infection.ToString()); SetInfection(null); navMeshAgent.speed = GetTraitValue("movement_speed") * 3.5F; } } if (!IsInside() && lastPosition == transform.position) { stuckCounter++; if (stuckCounter > 5) { if (CurrentState == EntityState.Going_Home && Vector3.Distance(transform.position, home.transform.position) < 10F) { EnterHome(); } movingTarget = null; targetPosition = NewTarget(); } } else { stuckCounter = 0; } lastPosition = transform.position; if (!IsInside() && outdatedPath && navMeshAgent.isOnNavMesh) { navMeshAgent.SetDestination(targetPosition); outdatedPath = false; } if (!IsInside() && Random.value < GetTraitValue("cough_rate") * 0.05F) { Energy -= 3; Cough(); } }
private void OnInfection(Infection infection) { if (infection.Host == MyInfoManager.Instance.Seq) { localController.Heal(0.2f); } if (infection.NewZombie == MyInfoManager.Instance.Seq && ZombieVsHumanManager.Instance.IsZombie(MyInfoManager.Instance.Seq)) { MakeZombie(); if (ZombieVsHumanManager.Instance.GetHumanCount() > 0) { newZombie = true; deltaNewZombie = 0f; } } }
//Unity initialization method void Start() { //Get reference to this player's camera and infection information playerCamera = transform.parent.GetComponentInChildren <Camera>(); infections = transform.parent.GetComponent <Infection>(); //Initialize flags split = false; //Initialize values scale = 1.0f; lookDirection = Vector3.zero; //Initialize arrays projectile = new GameObject[1]; }
void DamageSkull() { if (this.GetComponent <Infection>() != null) { Infection infection = this.GetComponent <Infection>(); if (infection._isFullyInfected) { _elapsedTime += Time.deltaTime; if (_elapsedTime >= 10.0f) { gameControl.DecreaseHealth(); _elapsedTime = 0.0f; } } } }
void GetInfected(GameObject other) { Infection otherInfection = other.gameObject.GetComponent <Infection>(); if (otherInfection != null && other.GetType() != typeof(SphereCollider) && otherInfection.canInfect == true && currentState == InfectionType.NotInfected) { //If other person is infected AND you are not infected if (otherInfection.currentState != InfectionType.NotInfected) { currentState = InfectionType.PotentialInfection; //manager.potentialInfected++; manager.notInfected--; CheckInfection(); } } }
public Infection InstantiateInfection(Node node) { GameObject newInfectionGO = GameObject.Instantiate(infectionPrefab) as GameObject; newInfectionGO.transform.SetParent(node.transform); Infection newInfection = newInfectionGO.GetComponent <Infection>(); newInfection.infectionManager = this; newInfection.node = node; node.infection = newInfection; newInfection.timeOfInfection = Time.time; infections.Add(newInfection); return(newInfection); }
// Use this for initialization void Start() { isPause = false; Slider[] sliderObjects = hud.gameObject.GetComponentsInChildren <Slider>(); foreach (Slider slider in sliderObjects) { if (slider.name == "Health") { healthSlider = slider; } else if (slider.name == "Infection") { infectionSlider = slider; } } infection = GetComponent <Infection>(); }
public void inflict(AttackInfo attackInfo) { Abstract_Identity activator = attackInfo.activator; // Victim must be human Human_Identity victim = attackInfo.victim.GetComponent <Human_Identity>(); if (victim != null) { Infection victimInfectionComponent = victim.getInfectionComponent(); Assert.IsNotNull(victimInfectionComponent); Zombie_Identity activatorZomb = (Zombie_Identity)activator; Assert.IsNotNull(activatorZomb); // Infect float infectiousness = activatorZomb.GetInfectiousness(); victimInfectionComponent.addInfection(infectiousness, activatorZomb); } }
public void InfectTooth() { if (teeth.Count > 0) { for (int attemptedToothCount = 0; attemptedToothCount < teeth.Count; attemptedToothCount++) { // Get our infection index. int index = Random.Range(0, teeth.Count); GameObject selectedTooth = teeth[index]; // Make sure we're infecting a valid tooth, and not infecting a tooth that's already infected. if (selectedTooth != null && /* */ selectedTooth.GetComponent <Infection>() == null) { Infection newInfection = selectedTooth.AddComponent <Infection>(); newInfection.infectedColor = infectionColor; } else { continue; } } } }
public Entity(Transform transformTemp) { /* * An alternative constructor for when additional parameters are not defined. * Creates an entity with default parameters. */ transform = transformTemp; //Creates an ID for the entity ID = tempID; tempID++; //Sets up movement composite object movement = transform.gameObject.GetComponent <Movement> (); movement.Initialise(this, 0); //Sets up infection composite object infection = transform.gameObject.GetComponent <Infection> (); infection.Initialise(1, 0, false); infection.ID = ID; sprite = transform.gameObject.GetComponent <SpriteRenderer> (); }
public void InfectTheTooth() { if (teeth.Count > 0) { // How many teeth we've tried to infect for (int attemptedToothCount = 0; attemptedToothCount < teeth.Count; attemptedToothCount++) { // Get a random tooth int index = Random.Range(0, teeth.Count); GameObject selectedTooth = teeth[index]; // Attach infection to the randomly selected tooth (if not already infected) if (selectedTooth.GetComponent <Infection>() == null) { Infection newInfection = selectedTooth.AddComponent <Infection>(); newInfection.infectedColor = infectionColor; } else { continue; } } } }
public static DonationErr Update(string DIN, Infection infection, TR? TR = null, string note = "") { if (infection == null) { return DonationErrEnum.NonTR; } else { Func<Infection, Infection, TR?, TR?> f = (infecIn, infecOut, TRValue) => { return infecIn == infecOut ? TRValue : null; }; return Update(DIN, f(infection, Infection.HIV_Ab, TR), f(infection, Infection.HCV_Ab, TR), f(infection, Infection.HBs_Ag, TR), f(infection, Infection.Syphilis, TR), f(infection, Infection.Malaria, TR), note); } }
private void updateDeltas(List <Infection> infections) { int ctr = 0; Infection priorInfection = null; foreach (Infection infection in infections) { if (ctr > 0) { infection.AggregatedConfirmedDelta = infection.AggregatedConfirmed - priorInfection.AggregatedConfirmed; if (priorInfection.AggregatedConfirmed != 0) { infection.AggregatedConfirmedPctChange = (infection.AggregatedConfirmedDelta * 100) / priorInfection.AggregatedConfirmed; } infection.ActiveConfirmedDelta = infection.ActiveConfirmed - priorInfection.ActiveConfirmed; if (priorInfection.ActiveConfirmed != 0) { infection.ActiveConfirmedPctChange = (infection.ActiveConfirmedDelta * 100) / priorInfection.ActiveConfirmed; } infection.RecoveredDelta = infection.Recovered - priorInfection.Recovered; if (priorInfection.Recovered != 0) { infection.RecoveredPctChange = (infection.RecoveredDelta * 100) / priorInfection.Recovered; } infection.DeathsDelta = infection.Deaths - priorInfection.Deaths; if (priorInfection.Deaths != 0) { infection.DeathsPctChange = (infection.DeathsDelta * 100) / priorInfection.Deaths; } if (infection.AggregatedConfirmedPctChange > 100) { infection.AggregatedConfirmedPctChange = 0; } if (infection.ActiveConfirmedPctChange > 100) { infection.ActiveConfirmedPctChange = 0; } if (infection.RecoveredPctChange > 100) { infection.RecoveredPctChange = 0; } if (infection.DeathsPctChange > 100) { infection.DeathsPctChange = 0; } } if (ctr > 1) { if (priorInfection.AggregatedConfirmedDelta != 0) { infection.AggregatedConfirmedPctDeltaChange = ((infection.AggregatedConfirmedDelta - priorInfection.AggregatedConfirmedDelta) * 100) / priorInfection.AggregatedConfirmedDelta; } if (priorInfection.ActiveConfirmedDelta != 0) { infection.ActiveConfirmedPctDeltaChange = ((infection.ActiveConfirmedDelta - priorInfection.ActiveConfirmedDelta) * 100) / priorInfection.ActiveConfirmedDelta; } if (priorInfection.RecoveredDelta != 0) { infection.RecoveredPctDeltaChange = ((infection.RecoveredDelta - priorInfection.RecoveredDelta) * 100) / priorInfection.RecoveredDelta; } if (priorInfection.DeathsDelta != 0) { infection.DeathsPctDeltaChange = ((infection.DeathsDelta - priorInfection.DeathsDelta) * 100) / priorInfection.DeathsDelta; } //infection.AggregatedConfirmedPctDeltaChange = (int) Math.Log(infection.AggregatedConfirmedPctDeltaChange); //infection.ActiveConfirmedPctDeltaChange = (int) Math.Log(infection.ActiveConfirmedPctDeltaChange); if ((infection.AggregatedConfirmedPctDeltaChange > 1000) || (infection.AggregatedConfirmedPctDeltaChange < -1000)) { infection.AggregatedConfirmedPctDeltaChange = 0; } if ((infection.ActiveConfirmedPctDeltaChange > 1000) || (infection.ActiveConfirmedPctDeltaChange < -1000)) { infection.ActiveConfirmedPctDeltaChange = 0; } if ((infection.RecoveredPctDeltaChange > 1000) || (infection.RecoveredPctDeltaChange < -1000)) { infection.RecoveredPctDeltaChange = 0; } if ((infection.DeathsPctDeltaChange > 1000) || (infection.DeathsPctDeltaChange < -1000)) { infection.DeathsPctDeltaChange = 0; } } priorInfection = infection; ctr++; } }