public bool PickUp(Villager.Items item) { if (!Items.Contains(item)) return false; Items.Remove(item); return true; }
void WalkingPathState() { progress += Time.deltaTime / enemyStats.speed * enemyStats.speedMultiplier; if (progress > 1f) { progress = 1f; updateState = KidnapingState; for(int i=0; i <villageManager.villagers.Count;++i) { Villager tmpVilla = villageManager.villagers[i]; if(tmpVilla.kidnapped == false) { kidnap = tmpVilla; kidnap.kidnapped = true; kidnap.GetComponent<AudioSource>().Play(); kidnap.OnDead(); break; } } if(kidnap == null) { LevelManager.GameOver(); } animator.SetTrigger("Kidnap"); } Vector3 position = spline.GetPoint(progress); angle = spline.GetDirection(progress); spriteRender.flipX = angle.x >= 0; // transform.Translate(angle* velocity * Time.deltaTime); transform.position = position + Quaternion.Euler(0, 0, 90) * spline.GetDirection(progress) * multiplier ; }
public static void Create(int id, Villager villager) { _buildingId = id; _villager = villager; DestroyCurrent (); InstantiateNewBuilding (string.Empty); // incompleto }
// Use this for initialization void Start () { remainingVillagers = new List<Villager>(); pastVillagers = new List<PastVillager>(); Villager[] villagers = remainingVillagersTrans.GetComponentsInChildren<Villager>(); remainingVillagers.AddRange(villagers); if(activeVillager == null) { Villager player = activeVillagerTrans.GetComponentInChildren<Villager>(); if (player == null) { NextVillager(); EnterArena(); } else { activeVillager = player; } activeVillager.activePlayer = true; playerActions = new List<Action>(); } }
public void AddCultist(Villager newCultist) { LoadingPower.gameObject.SetActive(true); IsActiveSpot = true; Virginity = newCultist.Virginity; ActiveVillager = newCultist; Debug.Log("Active"); }
void OnEnable() { progress = 0; updateState = WalkingPathState; multiplier = Random.Range(-pathDifference, pathDifference); EventOnStop += OnStop; kidnap = null; }
public Epidemic(Game g, Villager v) : base(g) { SickVillagerList = new List<Villager>(); //affectedVillager = v; //game = g; //LaunchEpidemic(); g.EpidemicCreated(this); _virus = new Virus(); _virus.Epidemic = this; v.SetVirus(_virus); _timeBeforeThePlayerIsWarned = 5; }
private Vector2 flee(Villager villager) { Vector2 fleeForce = new Vector2(villager.transform.position.x, villager.transform.position.z) - new Vector2(enemy.transform.position.x, enemy.transform.position.z); if (fleeForce.magnitude <= 10.0f) { fleeForce.Normalize(); } else { fleeForce *= 0; } return(fleeForce * 500.0f); }
void OnTriggerEnter2D(Collider2D collider) { Beast beast = collider.GetComponent<Beast>(); if(beast != null && beast.ReadyToAttack() && IsActiveSpot && ActiveVillager != null) { ActiveVillager.HandleBeingKilled(); LoadingPower.gameObject.SetActive(false); IsActiveSpot = false; ActiveVillager = null; beast.Attack(); GameController.Instance.CheckForAnyCultistsLeft(); } }
void Sacrifice(Villager villager) { m_CurrentSacrificeCount++; SacrificeCountText.text = string.Format("{0}/{1}", m_CurrentSacrificeCount, m_SacrificeCount); OnSacrifice?.Invoke(villager); this.GetComponentInChildren <Button>().interactable = true; if (m_CurrentSacrificeCount == m_SacrificeCount) { CloseView(); } }
public ActionResult Raided() { int foodRaided = ran.Next(1, 4); int waterRaided = ran.Next(1, 4); int villagerCount = db.Villagers.ToArray().Length; List <Villager> villagers = db.Villagers.ToList(); int VillagerIndex = ran.Next(1, villagerCount); var resource = db.Resources.Find(1); Villager unluckyGuy = villagers[VillagerIndex]; string nameOfTheDeceased = unluckyGuy.Name; if ((bool)Session["Raided"] == true) { if (resource.Food < foodRaided) { resource.Food = 0; } else { db.Resources.Find(1).Food -= foodRaided; } if (resource.Water < waterRaided) { resource.Water = 0; } else { db.Resources.Find(1).Water -= waterRaided; } Session["LostFood"] = "You've lost " + foodRaided + " food"; Session["LostWater"] = "You've lost " + waterRaided + " water"; if () { Session["LostVillager"] = nameOfTheDeceased + "has died and their house was burned to the ground"; } db.Buildings.Find(1).Houses--; db.Villagers.Remove(unluckyGuy); db.SaveChanges(); Session["Raided"] = false; } else { ViewBag.NotRaided = "You're trying to get raided? Who's side are you on?"; } return(View()); }
void Start() { Villager villager = SpawnVillager(); villager.Talk(); House house = SpawnHouse(); house.SwitchLights(); Animal animal = SpawnAnimal(); animal.Eat(); }
void Update() { NavMeshAgent nav = GetComponent<NavMeshAgent>(); target = getNearestVillager(); nextBowFire -= Time.deltaTime; if (item == Item.SWORD) { if (target != null) { if (Vector3.Distance(transform.position, target.transform.position) < 2f) { if (nextBowFire <= 0) { nextBowFire = bowReload; target.addHealth(-attack); //Random source.clip = attackClip[Random.Range(0, attackClip.Length)]; source.Play(); nav.SetDestination(transform.position); } } else { nav.SetDestination(target.transform.position); } } } else if (item == Item.BOW) { if (target != null) { if (Vector3.Distance(transform.position, target.transform.position) < 7f) { nav.SetDestination(transform.position); if (nextBowFire <= 0) { nextBowFire = bowReload; target.addHealth(-attack); source.clip = attackClip[Random.Range(0, attackClip.Length)]; source.Play(); } } if (target != null) { if (Vector3.Distance(transform.position, target.transform.position) < 1.2f) { target.addHealth(-attack); source.Play(); nav.SetDestination(transform.position); } else { nav.SetDestination(target.transform.position); } } } } }
public void returnHome() { foreach (GameObject obj in villagers) { Villager vil = GetComponent(typeof(Villager)) as Villager; if (vil != null) { if (vil.inGatherZone) { vil.returnLoad(); } } } }
private void checkReloadVillager() { if (ReloadVillagerToggle.isOn) { Villager v = loadVillagerExternal(currentlyLoadedVillagerIndex, true); if (v != null) { loadedVillager.SetMemories(v.GetMemories()); loadedVillager.SetEventFlagsSave(v.GetEventFlagsSave()); loadedVillager.MovingOut = v.MovingOut; loadedVillager.CatchPhrase = v.CatchPhrase; } } }
public Villager FindAvailableWorker(Building home, Vector2 offset) { if (AvailableVillagersData.Count > 0) { Villager v = AvailableVillagersData[0]; AvailableVillagersData.Remove(v); v.home.RemoveVillager(v); Tile t = WorldController.Instance.GetTileAt(home.tile.x + (int)offset.x, home.tile.y + (int)offset.y); v.SetHomeAndOffset(home, t); VillagersData.Add(v); return(v); } return(null); }
private void Schedule() { sorted = main.villagers.OrderByDescending(o => o.happiness).ToList(); Schedule[] schedules = new Schedule[sorted.Count]; if (main.GetSeason() != VillageManager.Season.Winter) { //what needs to be produced int breadneeded = sorted.Count; //every villager needs 1 bread a day int flourneeded = (breadneeded / 4) + 1; // 1 flour = 4 breads int wheatneeded = flourneeded * 3; // 3 wheat for 1 four needed int breaddiff = breadneeded - main.bread; int flourdiff = flourneeded - main.flour; int wheatdiff = wheatneeded - main.wheat; float timebread = (breaddiff / 4) * VillageManager.oneHour; float timeflour = flourdiff * VillageManager.oneHour; float timewheat = (wheatdiff / 3) * VillageManager.oneHour; float time = sorted.Count * VillageManager.oneDay; //time available to all villagers float timeasleep = sorted.Count * (VillageManager.oneHour * 8); //sleep time -= timeasleep; time -= timebread; time -= timeflour; time -= timewheat / 3; if (time > 0) { float duration = timebread + timeflour + timewheat + timeasleep; //enough time, proceed int villagersneeded = (int)duration / VillageManager.oneDay; List <Task> tasks = new List <Task>(); for (int i = 0; i < villagersneeded; i++) { Villager v = sorted[i]; Schedule s = v.schedule = new Schedule(); s.tasks.Clear(); } } else { //im not sure tbh } } }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.GetComponent <Villager>()) { Villager citizen = collision.gameObject.GetComponent <Villager>(); OPZombie zombie = (OPZombie)citizen; print("From OPzombie " + zombie.info.age); global.villagerCount--; //Substract a villager global.villagerText.text = "Villagers = " + global.villagerCount.ToString(); //Actualize the text global.oPZombieCount += 1; // Add a zombie global.oPZombieText.text = "OPZombies = " + global.oPZombieCount.ToString(); //Debug.Log(global.oPZombieCount); } }
public override void update(Villager villager, float deltaTime) { Vector2 steering = flee(villager); Vector2 vel = steering * deltaTime; Vector2 pos = new Vector2(villager.transform.position.x, villager.transform.position.z); Vector2 newPos = pos + vel * deltaTime; Vector3 finalPos = new Vector3(newPos.x, villager.transform.position.y, newPos.y); villager.transform.position = finalPos; if ((villager.transform.position - finalPos).magnitude >= 10.0f) { villager.updateState(new WanderState()); villager.run(); } }
private void loadAllVillagers() { for (int i = 0; i < 10; ++i) { byte[] loaded = CurrentConnection.ReadBytes(CurrentVillagerAddress + (uint)(i * Villager.SIZE), 3); Villager villagerShell = new Villager(loaded); Texture2D pic = SpriteBehaviour.PullTextureFromParser(villagerSprites, villagerShell.InternalName); if (pic != null) { TenVillagers[i].texture = pic; } } loadedVillagerShells = true; BlockerRoot.gameObject.SetActive(false); }
public static void DumpVillagerMemoryPlayer(Villager v, GSaveMemory memory) { using var sfd = new SaveFileDialog { Filter = "New Horizons Villager Player Memory (*.nhvpm)|*.nhvpm|All files (*.*)|*.*", FileName = $"{v.InternalName}.nhvpm", }; if (sfd.ShowDialog() != DialogResult.OK) { return; } var data = memory.Data; File.WriteAllBytes(sfd.FileName, data); }
public int ExecuteJobToLimit(ResourceDefinition definition, int resourceAmount, int limit) { var settlement = new Settlement(); var villager = new Villager(); var job = new CollectJob(new ResourceSource(definition, resourceAmount), limit); job.AssignedVillagers.Add(villager); Assert.IsFalse(job.LimitReached); for (var i = 0; i < resourceAmount; i++) { job.Execute(settlement); } Assert.AreEqual(1, job.AssignedVillagers.Count()); return(settlement.StockPile[definition]); }
private void B_LoadVillager_Click(object sender, EventArgs e) { var name = L_ExternalName.Text; using var ofd = new OpenFileDialog { Filter = "New Horizons Villager (*.nhv)|*.nhv|All files (*.*)|*.*", FileName = $"{name}.nhv", }; if (ofd.ShowDialog() != DialogResult.OK) { return; } var file = ofd.FileName; var original = SAV.Main.GetVillager(VillagerIndex); var expectLength = original.Data.Length; var fi = new FileInfo(file); if (fi.Length != expectLength) { var msg = $"Imported villager's data length (0x{fi.Length:X}) does not match the required length (0x{expectLength:X})."; WinFormsUtil.Error("Cancelling:", msg); return; } var data = File.ReadAllBytes(ofd.FileName); var v = new Villager(data); var player0 = SAV.Players[0].Personal; if (!v.IsOriginatedFrom(player0)) { var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, $"Imported Villager did not originate from Villager0 ({player0.PlayerName})'s data.", "Update values?"); if (result == DialogResult.Cancel) { return; } if (result == DialogResult.Yes) { v.ChangeOrigins(player0, v.Data); } } SAV.Main.SetVillager(v, VillagerIndex); LoadVillager(v); }
public Game() { this.CurrentLevel = 1; this.HomeBaseData = new HomeBase(); this.ResourcePoolData = new ResourcePool(); this.VillagersDict = new Dictionary <int, Villager> (); // Generate the starting villagers for (int i = 0; i < 5; i++) { Villager curVillager = new Villager(); VillagersDict.Add(curVillager.UnitID, curVillager); } }
public void TriggerEvent(VillagerEvent villagerEvent, Villager villager) { switch (villagerEvent) { case VillagerEvent.VillagerArrived: VillagerArrivedPanel.ShowMessage(string.Format("{0} has arrived in the village. Find them a place to live.", villager.Fullname)); break; case VillagerEvent.VillagerLeft: VillagerArrivedPanel.ShowMessage(string.Format("{0} has decided to find a home elsewhere and is leaving.", villager.Fullname)); break; case VillagerEvent.VillagerFirstNightAtHome: VillagerArrivedPanel.ShowMessage(string.Format("{0} spent their first night at home. Looks like they're staying.", villager.Fullname)); break; } }
public void RemoveVillager(Villager v) { v.home.RemoveVillager(v); if (VillagersData.Contains(v)) { VillagersData.Remove(v); } if (AvailableVillagersData.Contains(v)) { AvailableVillagersData.Remove(v); } if (VillagerGameObjcts.ContainsKey(v)) { Destroy(VillagerGameObjcts [v]); VillagerGameObjcts.Remove(v); } }
private void loadAllVillagers() { try { // load all houses loadAllHouses(); loadedVillagerShellsList = new List <Villager>(); for (int i = 0; i < 10; ++i) { byte[] loaded = CurrentConnection.ReadBytes(CurrentVillagerAddress + (uint)(i * Villager.SIZE), 3); Villager villagerShell = new Villager(loaded); loadedVillagerShellsList.Add(villagerShell); if (villagerShell.Species == (byte)VillagerSpecies.non) { TenVillagers[i].GetComponent <Button>().interactable = false; continue; } else { TenVillagers[i].GetComponent <Button>().interactable = true; } var ourHouse = loadedVillagerHouses.Find(x => x.NPC1 == (sbyte)i); if (ourHouse != null) { if (checkIfMovingIn(ourHouse)) { TenVillagers[i].GetComponent <Button>().interactable = false; // but still show them } } Texture2D pic = SpriteBehaviour.PullTextureFromParser(villagerSprites, villagerShell.InternalName); if (pic != null) { TenVillagers[i].texture = pic; } } loadedVillagerShells = true; BlockerRoot.gameObject.SetActive(false); } catch (Exception e) { PopupHelper.CreateError(e.Message, 2f); } }
private void B_LoadVillager_Click(object sender, EventArgs e) { var name = L_ExternalName.Text; using var ofd = new OpenFileDialog { Filter = "New Horizons Villager (*.nhv)|*.nhv|All files (*.*)|*.*", FileName = $"{name}.nhv", }; if (ofd.ShowDialog() != DialogResult.OK) { return; } var path = ofd.FileName; var original = Villagers[VillagerIndex]; var expectLength = original.Data.Length; var fi = new FileInfo(path); if (fi.Length != expectLength) { WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength), path); return; } var data = File.ReadAllBytes(ofd.FileName); var v = new Villager(data); var player0 = Origin; if (!v.IsOriginatedFrom(player0)) { string msg = string.Format(MessageStrings.MsgDataDidNotOriginateFromHost_0, player0.PlayerName); var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, msg, MessageStrings.MsgAskUpdateValues); if (result == DialogResult.Cancel) { return; } if (result == DialogResult.Yes) { v.ChangeOrigins(player0, v.Data); } } LoadVillager(Villagers[VillagerIndex] = v); }
public VillagerMemoryEditor(Villager villager) { InitializeComponent(); this.TranslateInterface(GameInfo.CurrentLanguage); Villager = villager; Memories = villager.GetMemories(); for (int i = 0; i < Memories.Length; i++) { LB_Players.Items.Add($"{i} - {Memories[i].PlayerName} ({Memories[i].TownName})"); } LB_Players.SelectedIndex = 0; DialogResult = DialogResult.Cancel; LB_Counts.SelectedIndex = 0; }
public void OnCollisionEnter(Collision wCollision) { if (wCollision.gameObject.tag == "Villager") { GameObject deadVillager = wCollision.gameObject; Villager death = wCollision.gameObject.GetComponent <Villager>(); gameManager.Villagers.Remove(deadVillager); gameManager.vFollowers.Remove(death.Follower.gameObject); gameManager.Followers.Remove(death); Destroy(death.Follower.gameObject); Destroy(death.Follower); Destroy(deadVillager); gameManager.createNewVillager(); gameManager.Dead.DeadVillagers = gameManager.Dead.DeadVillagers + 1; findTarget(); } }
static void MoveVillagersOutOfWay(Tile baseTile, Villager v) { //MoveVillagersOutOfWay must come after making a new graphical object, else tile.Installed == null List <Tile> tiles = baseTile.Planned.Tiles; for (int i = 0; i < tiles.Count; i++) { if (tiles[i].OccupyingVillagers.Count > 0 && !tiles[i].Planned.CanMoveThrough) { Debug.Log("Villager moved from " + tiles[i].GetPosition() + " to " + tiles[i].NearestNeighbourTo(tiles[i].X, tiles[i].Y).GetPosition()); foreach (Villager vil in tiles[i].OccupyingVillagers) { vil.CurrentTile = tiles[i].NearestNeighbourTo(tiles[i].X, tiles[i].Y); } } } }
public Villager createVillager(Building home, Vector2 pos) { Villager data = new Villager(home); GameObject go = Instantiate(villager); go.transform.position = pos; go.transform.SetParent(this.transform); VillagerController vc = go.AddComponent <VillagerController> (); vc.AddVillagerData(data); vc.AddHomeTile(pos); AvailableVillagersData.Add(data); VillagerGameObjcts.Add(data, go); return(data); }
public void AddVillager() { GameObject newVillager = Instantiate( villagerPrefab, Vector3.zero, Quaternion.identity ); newVillager.transform.SetParent(transform); Villager villager = newVillager.GetComponent <Villager>(); villagers.Add(villager); // villagers[villagers.Count - 1].Stable(); ReorderVillagers(); }
//Handles Collision with Cart for Scoring and Clean Up Purposes public void OnCollisionEnter(Collision wCollision) { if (wCollision.gameObject.tag == "Cart") { GameObject savedVillager = this.gameObject; Villager safe = this; gameManager.Villagers.Remove(savedVillager); gameManager.vFollowers.Remove(follower.gameObject); gameManager.Followers.Remove(safe); Destroy(follower.gameObject); Destroy(follower); Destroy(savedVillager); Destroy(this); gameManager.createNewVillager(); gameManager.Saved.SavedVillagers = gameManager.Saved.SavedVillagers + 1; Destroy(savedVillager); } }
public override void CalculateDesireValue(Villager villager) { var bias = villager.RepairHouseBias; var lowestHealth = villager.homes[0]; //Get House On Lowest Health foreach (var house in villager.homes.Where(house => house.HouseHealth < lowestHealth.HouseHealth)) { lowestHealth = house; } var factorOne = 1 - (lowestHealth.HouseHealth / lowestHealth.MaxHouseHealth); DesireVal = bias * factorOne; villager.DisplayRepairHouseDesire = DesireVal; }
public static void Prefix(Villager __instance, FreeResource resource) { bool enabled = ModMain.settings.enabled.Value && ModMain.settings.graveDiggingSettings.enabled.Value; bool removeGraveAfterDigging = ModMain.settings.graveDiggingSettings.removeGraveAfterDigging.Value; if (resource.type == FreeResourceType.Pork && enabled && removeGraveAfterDigging) { Vector3 position = resource.transform.position; int x = (int)position.x; int z = (int)position.z; if (Cemetery.IsCemetery(x, z)) { // Refer to Cemetery::IsCemetery. Building building = World.inst.GetCellData(x, z).StructureFindByCategory(World.cemeteryHash); Cemetery cemetery = building.GetComponentInParent <Cemetery>(); RemoveRandomGraveFromCemetery(cemetery); } } }
public static bool LoadVillagerMemoryPlayer(Villager v, GSaveMemory[] memories, int index) { using var ofd = new OpenFileDialog { Filter = "New Horizons Villager Player Memory (*.nhvpm)|*.nhvpm|All files (*.*)|*.*", FileName = $"{v.InternalName}.nhvpm", }; if (ofd.ShowDialog() != DialogResult.OK) { return(false); } var file = ofd.FileName; var fi = new FileInfo(file); const int expectLength = GSaveMemory.SIZE; if (fi.Length != expectLength) { WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength)); return(false); } var data = File.ReadAllBytes(file); var memory = new GSaveMemory(data); var old = memories[index]; if (!memory.IsOriginatedFrom(old)) { string msg = string.Format(MessageStrings.MsgDataDidNotOriginateFromHost_0, old.PlayerName); var result = WinFormsUtil.Prompt(MessageBoxButtons.YesNoCancel, msg, MessageStrings.MsgAskUpdateValues); if (result == DialogResult.Cancel) { return(false); } if (result == DialogResult.Yes) { memory.ChangeOrigins(old, memory.Data); } } memories[index] = memory; return(true); }
private GameObject spawnVillager() { GameObject newVillager = lastSpawnIsMale ? Instantiate(villagerGOFemale) : Instantiate(villagerGOMale); lastSpawnIsMale = !lastSpawnIsMale; Villager newVillagerBehaviour = newVillager.GetComponent <Villager>(); __villager_entities.Add(newVillagerBehaviour); //Randomize color SpriteRenderer sr = newVillager.GetComponent <SpriteRenderer>(); /* * sr.color = Random.ColorHSV(); */ return(newVillager); }
public IPeople GetPeople(PeopleType peopleType) { IPeople people = null; switch (peopleType) { case PeopleType.RURAL: people = new Villager(); break; case PeopleType.URBAN: people = new UrbanPeople(); break; default: break; } return(people); }
public static void CheckRelationship(Villager vill1, Villager vill2) { if(vill2.relationships == null) vill2.relationships = new List<VillagerRelationship>(); VillagerRelationship relVill = vill1.relationships.Find(x => x.targetVillagerID == vill2.uniqueID); VillagerRelationship relVill2 = vill2.relationships.Find(x => x.targetVillagerID == vill1.uniqueID); float interestRating = InterestRating(vill1, vill2) * 2f / 10000f - 0.0001f; //Debug.Log(interestRating); if(relVill == null){ relVill = new VillagerRelationship(vill2.uniqueID); relVill.relationshipValue = Mathf.Clamp(relVill.relationshipValue + interestRating, 0f, 2f); vill1.relationships.Add(relVill); }else{ relVill.relationshipValue = Mathf.Clamp(relVill.relationshipValue + interestRating, 0f, 2f); } if(relVill2 == null){ relVill2 = new VillagerRelationship(vill1.uniqueID); relVill2.relationshipValue = Mathf.Clamp(relVill2.relationshipValue + interestRating, 0f, 2f); vill2.relationships.Add(relVill2); }else{ relVill2.relationshipValue = Mathf.Clamp(relVill2.relationshipValue + interestRating, 0f, 2f); } }
public void VillagerMunch(Villager eatVillager) { int wat = eatVillager.foodList.Count; wat -= wat / 2; float deltaFood = (Time.time - eatVillager.timeStamp) * foodMult * foodConsumptionRate; foreach(ResourceManager.Resource foodle in eatVillager.foodList){ if(foodle.amount <= 0f){ wat--; continue; } ResourceManager.Resource realFoodle = GM.resourceManager.GetResource(foodle.name); float tAmount = realFoodle.amount; //amount eaten tAmount -= deltaFood; if(tAmount < 0f) tAmount = 0f; tAmount = realFoodle.amount - tAmount; realFoodle.amountEaten += tAmount; eatVillager.mood += (tAmount / deltaFood)* MoodMult * wat; deltaFood -= tAmount; wat--; foreach(FoodEffect fect in realFoodle.foodEffects){ int enumIndex = (int)fect.foodEffectType; switch (enumIndex){ case 1: //HealthBuff break; case 2: //MoodBuff break; } } if(deltaFood <= 0f) break; } if(deltaFood > 0f){ eatVillager.health -= deltaFood; } }
public void HireVillager(Villager villager, StructureManager.Structure struc) { IEnumerable<PhysicalStructure> hiringList = GM.builderHelper.hiringPStructList.Where(x => x.structure == struc); if(hiringList.Count() > 0){ PhysicalStructure hiringStruc = hiringList.First(); if(struc.isHouse){ villager.livesAt = hiringStruc.spotIndex; }else{ villager.worksAt = hiringStruc.spotIndex; } struc.workers.Add(villager); if(hiringStruc.employeeList.Count == 0) struc.activeAmount++; hiringStruc.employeeList.Add(villager); if(hiringStruc.employeeList.Count == struc.workerCapacity) struc.fullyActiveAmount++; } }
private void loadVillager(int i) { Villagers[i] = new Villager(Save.Data, 0x027D10 + 0x24F8 * i, 0x24F8); TownVillagers[i].Enabled = TownVillagersCatch[i].Enabled = (Villagers[i].ID != -1); TownVillagers[i].SelectedValue = (int)Villagers[i].ID; TownVillagersCatch[i].Text = Villagers[i].CatchPhrase; }
void selection() { if ((Input.GetKeyDown(KeyCode.Mouse0) || Input.GetKeyDown(KeyCode.Mouse1))) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); bool commandGiven = false; //find resource or cake if (Physics.Raycast(ray, out hit, 1000, 1 << LayerMask.NameToLayer("Resource"))) { var resource = hit.collider.GetComponent<ResourceView>(); foreach (var aVillager in villagers) { aVillager.getResource(resource); aVillager.Deselect(); commandGiven = true; } } else if (Physics.Raycast(ray, out hit, 1000, 1 << LayerMask.NameToLayer("Cake"))) { foreach (var aVillager in villagers) { aVillager.GoToBake(); aVillager.Deselect(); commandGiven = true; } } if (commandGiven) { villagers.Clear(); return; } //find villager if (Physics.Raycast(ray, out hit, 1000, 1 << LayerMask.NameToLayer("Villager"))) { targetVillager = hit.transform.GetComponentInParent<Villager>(); if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightShift) || Input.GetKey(KeyCode.RightControl)) { villagers.Add(targetVillager); targetVillager.Select(); } else { foreach (var villager in villagers) villager.Deselect(); villagers.Clear(); villagers.Add(targetVillager); targetVillager.Select(); } } else { isSelecting = true; mousePosition1 = Input.mousePosition; } } else if (isSelecting && (Input.GetMouseButtonUp(0) || Input.GetKeyUp(KeyCode.Mouse1))) { foreach (var villager in villagers) villager.Deselect(); villagers.Clear(); isSelecting = false; var allVillagers = new List<Villager>(FindObjectsOfType<Villager>()); var camera = Camera.main; var viewportBounds = Utils.GetViewportBounds(camera, mousePosition1, Input.mousePosition); foreach (var villager in allVillagers) { var bounds = villager.transform.GetComponentInChildren<BoxCollider>().bounds; Vector3 point1 = bounds.center + Vector3.up * bounds.extents.y + Vector3.right * bounds.extents.x + Vector3.forward * bounds.extents.z; Vector3 point2 = bounds.center + Vector3.up * bounds.extents.y - Vector3.right * bounds.extents.x + Vector3.forward * bounds.extents.z; Vector3 point3 = bounds.center + Vector3.up * bounds.extents.y + Vector3.right * bounds.extents.x - Vector3.forward * bounds.extents.z; Vector3 point4 = bounds.center + Vector3.up * bounds.extents.y - Vector3.right * bounds.extents.x - Vector3.forward * bounds.extents.z; Vector3 point5 = bounds.center - Vector3.up * bounds.extents.y + Vector3.right * bounds.extents.x + Vector3.forward * bounds.extents.z; Vector3 point6 = bounds.center - Vector3.up * bounds.extents.y - Vector3.right * bounds.extents.x + Vector3.forward * bounds.extents.z; Vector3 point7 = bounds.center - Vector3.up * bounds.extents.y + Vector3.right * bounds.extents.x - Vector3.forward * bounds.extents.z; Vector3 point8 = bounds.center - Vector3.up * bounds.extents.y - Vector3.right * bounds.extents.x - Vector3.forward * bounds.extents.z; if ( JustDoIt(viewportBounds, point1, camera) || JustDoIt(viewportBounds, point2, camera) || JustDoIt(viewportBounds, point3, camera) || JustDoIt(viewportBounds, point4, camera) || JustDoIt(viewportBounds, point5, camera) || JustDoIt(viewportBounds, point6, camera) || JustDoIt(viewportBounds, point7, camera) || JustDoIt(viewportBounds, point8, camera) ) { villagers.Add(villager); villager.Select(); } } } }
public void FireVillager(Villager villager, bool housing = false) { PhysicalStructure tmpPStruct; if(!housing){ if(villager.worksAt == null) return; tmpPStruct = PStructFromIndex(villager.worksAt); }else tmpPStruct = PStructFromIndex(villager.livesAt); if(tmpPStruct == null) return; StructureManager.Structure struc = tmpPStruct.structure; struc.workers.Remove(villager); if(tmpPStruct.employeeList.Count == struc.workerCapacity) struc.fullyActiveAmount--; tmpPStruct.employeeList.Remove(villager); if(tmpPStruct.employeeList.Count == 0) struc.activeAmount--; if(housing){ villager.livesAt = null; }else{ villager.worksAt = null; } }
public void RemoveVillagerFromColliding(Villager villager) { villager.HideThought(); if (collidingVillagers.Contains(villager)) { collidingVillagers.Remove(villager); villager.GetComponent<Flash>().HideFlash(); } }
public void VillagerInfo(Villager villager) { if(GM.builderHelper.isPlacing) return; Transform templates = canvasObj.transform.Find ("Templates"); GameObject sInfoTemp = templates.Find ("VillagerInfo").gameObject; bool createNew = false; if(toolTip){ if(lastTooltip != "VillagerInfo"){ Destroy(toolTip); createNew = true; } }else createNew = true; if(createNew){ toolTip = GameObject.Instantiate (sInfoTemp); toolTip.transform.SetParent (templates); toolTip.name = "VillagerInfoTooltip"; toolTip.SetActive (true); toolTip.transform.localScale = Vector3.one; toolTip.GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, -15f); } lastTooltip = "VillagerInfo"; toolSwitch = 5; lastToolVillager = villager; Sprite strucIcon = Resources.Load<Sprite> ("VillagerIcons/Heads/VH" + villager.headIconIndex); toolTip.transform.Find ("VillagerIcon").GetComponent<Image> ().sprite = strucIcon; toolTip.transform.Find ("NameText").GetComponent<Text>().text = villager.name; PhysicalStructure vWork = GM.villagerManager.PStructFromIndex(villager.worksAt); PhysicalStructure vHome = GM.villagerManager.PStructFromIndex(villager.livesAt); if(vWork) toolTip.transform.Find ("WorkText").GetComponent<Text>().text = "Works at a " + vWork.structure.displayName; else toolTip.transform.Find ("WorkText").GetComponent<Text>().text = "Unemployed"; if(vHome) toolTip.transform.Find ("HomeText").GetComponent<Text>().text = "Lives in a " + vHome.structure.displayName; else toolTip.transform.Find ("HomeText").GetComponent<Text>().text = "Homeless"; }
public void DoTick(Structure struc) { //fire the worst people to keep up with demand if(struc.demandAmount < struc.activeAmount){ if(struc.workers.Count > 0){ float worst = 100f; Villager worstVill = new Villager(); foreach(Villager vill in struc.workers){ float tSkill = vill.GetSkill(struc.structCategory.ToString()).skillLevel; if(tSkill < worst){ worst = tSkill; worstVill = vill; } } GM.villagerManager.FireVillager(worstVill, struc.isHouse); GM.shouldRefreshStructs = true; CalculateAverages(struc); } }else CalculateAverages(struc); //else if(struc.activeAmount < struc.demandAmount){ // RefreshHiringStructures(); //} foreach(Cost cst in struc.activeCosts){ ResourceManager.Resource tmpRes = GM.resourceManager.GetResource (cst.resource); if(tmpRes.amount < (cst.amount * struc.activeAmount / GM.ticks) * struc.activeCostMult) return; tmpRes.amount -= (cst.amount * struc.activeAmount / GM.ticks) * struc.activeCostMult; tmpRes.contributors.activeProduction -= (cst.amount * struc.activeAmount) * struc.activeCostMult; } foreach(Effect effct in struc.activeEffects) { int enumIndex = (int)effct.effectType; if(effct.effectTarget == Effect.targetMode.Resource) { ResourceManager.Resource tmpRes = GM.resourceManager.GetResource (effct.targetName); switch (enumIndex) { case 1: //Produce //tmpRes.amount += (effct.effectValue * struc.activeAmount / GM.ticks) * struc.activeMult; tmpRes.contributors.activeProduction += effct.effectValue * struc.amount * struc.activeMult * struc.averageCapacity * struc.averageSkill; break; case 3: //SumStorage tmpRes.sumStorage += (effct.effectValue * struc.activeAmount) * struc.activeMult; break; } } } }
void Awake() { myVillager = this.transform.GetComponentInParent<Villager>(); }
public void SetAction(Villager.Actions NewAction,Tree TreeInUse, float ActionTime_ = 0) { CurrentActionTime = 0; CurrentAction = NewAction; ActionTime = ActionTime_; ToCut = TreeInUse; Timer = true; }
public void SetAction(Villager.Actions NewAction,float ActionTime_ = 0) { CurrentActionTime = 0; CurrentAction = NewAction; ActionTime = ActionTime_; Timer = true; }
public void SetAction(Villager.Actions NewAction, Building Location, Items Item, float ActionTime_ = 0) { Timer = true; CurrentActionTime = 0; ActionTime = ActionTime_; // for pick up and put down Is instant if (NewAction == Actions.Pickup) if (Location.PickUp(Item)) Inventory = Item; else if (NewAction == Actions.Putdown) { Location.DropOff(Item); Inventory = Items.Empty; } //blacksmith production if(Item == Items.Axe) { } else if (Item == Items.Cart) { } else if (Item == Items.Rifle) { } }
public void SetAction(Villager.Actions NewAction,Building Location,float ActionTime_ = 0) { ActionTime = ActionTime_; CurrentActionTime = 0; CurrentAction = NewAction; LocationAction = Location; Timer = true; }
public void LearnSkill(Villager.Skills newSkills, Villager Teach) { Skill = newSkills; Teach.StartTimer(); StartTimer(); }
static float InterestRating(Villager vill1, Villager vill2) { float Similarness = 0; Similarness += ListPercentSimilar(vill1.foodList, vill2.foodList); //Similarness += ListPercentSimilar(vill1.skillList, vill2.skillList); Similarness /= 1f; return Similarness; }
public void notifyReturn(Villager villager) { justReturnedVillagers.Add(villager); }
void DropVillager(bool animated = true) { if(animated) playerAnimations.AnimationPut(); IsCarryingVillager = false; if(collidingVillagers.Count > 0) collidingVillagers[collidingVillagers.Count - 1].GetComponent<Flash>().HideFlash(); if(CarriedVillager != null) { CarriedVillager.HandleBeingDropped(); CarriedVillager = null; } }
public bool CreateVillager() { if (villagers.Count + outVillagers.Count < maxVillagers) { int villagerCount = villagers.Count + outVillagers.Count; Villager newVillager = new Villager(villagerTexture, cowManager, this, new Vector2(650 + villagerCount * 8, 400 + (16 * (villagerCount % 2)))); villagers.Enqueue(newVillager); collisionManager.addOther(newVillager); return true; } return false; }
public void HandleSpaceAction() { if(CurrentState == EPlayerState.Dropping || CurrentState == EPlayerState.Dying || CurrentState == EPlayerState.PickingUp) return; if(IsCarryingVillager) { CurrentState = EPlayerState.Dropping; if(IsOnAltar) { DropVillagerAsSacrifice(); } else if(IsOnPrayerSpot && !currentPrayerSpot.IsActiveSpot) { DropVillagerAsCultist(); } else { DropVillager(); } } else { if(collidingVillagers.Count > 0) { IsCarryingVillager = true; playerAnimations.AnimationTake(); CurrentState = EPlayerState.PickingUp; CarriedVillager = collidingVillagers[0]; CarriedVillager.HandleBeingPickedUp(); GetComponent<AudioSource>().Play(); } } }
public void AddVillagers(int amount) { for(int i = 0; i < amount; i++){ Villager tmpVillager = new Villager(); villagers.Add(tmpVillager); tmpVillager.name = "Villager " + villagers.Count.ToString(); tmpVillager.GM = GM; tmpVillager.Start(); tmpVillager.uniqueID = iDentifier; iDentifier++; } }