public LabourerProfileVM GetLabourer(int labourerID) { Labourer Labourer = _context.Labourer.FirstOrDefault(l => l.LabourerId == labourerID); var avgerageSafety = _context.JobLabourer .Where(j => j.LabourerId == labourerID && j.LabourerSafetyRating != null).Average(av => av.LabourerSafetyRating); var avgerageQuality = _context.LabourerAttendance .Where(l => l.LabourerId == labourerID && l.DailyQualityRating != null).Average(av => av.DailyQualityRating); LabourerProfileVM lp = new LabourerProfileVM() { Labourer = Labourer, Skills = _context.LabourerSkill.Where(ls => ls.LabourerId == labourerID).Select(ols => new Skill() { SkillId = ols.Skill.SkillId, SkillName = ols.Skill.SkillName, AdminReceives = ols.Skill.AdminReceives, LabourerReceives = ols.Skill.LabourerReceives }), AverageSafety = avgerageSafety, SafetyRatingNumber = _context.JobLabourer .Where(j => j.LabourerId == labourerID && j.LabourerSafetyRating != null).Count(), AverageQuality = avgerageQuality, QualityRatingNumber = _context.LabourerAttendance .Where(l => l.LabourerId == labourerID && l.DailyQualityRating != null).Count() }; return(lp); }
public IEnumerator BuildLaborerUpgrade(Labourer lab) { //print("Upgrading"); IsUpgrading = true; WhatsBeingBuild = lab; yield return(new WaitForSeconds(lab.BuildTime * 1.5f)); MySupplies.RemoveFireWood(lab.Costs[(int)Resources.Firewood], true); MySupplies.RemoveLogs(lab.Costs[(int)Resources.Log], true); MySupplies.RemoveOres(lab.Costs[(int)Resources.Ore], true); MySupplies.RemoveTools(lab.Costs[(int)Resources.Tools], true); if (lab.GetType() == typeof(WoodCutter)) { MySupplies.WoodCutterUpgrade *= 1.1f; } else if (lab.GetType() == typeof(Blacksmith)) { MySupplies.BlackSmithUpgrade *= 1.1f; } else if (lab.GetType() == typeof(Miner)) { MySupplies.MinerUpgrade *= 1.1f; } else if (lab.GetType() == typeof(Logger)) { MySupplies.LoggerUpgrade *= 1.1f; } IsUpgrading = false; WhatsBeingBuild = null; }
private IEnumerator CoolDown() { yield return(new WaitForSeconds(5)); _target = null; StartTime = 0; _stolen = false; }
public IActionResult Write(int LabourerID, string FirstName, string LastName, int Gender, string Address, string ZipCode, string PhoneNumber, string Email) { //Insert een Labourer in de database Labourer lab = new Labourer(LabourerID, FirstName, LastName, Gender, Address, ZipCode, PhoneNumber, Email); MollShopContext context = HttpContext.RequestServices.GetService(typeof(TestWebApp.Models.MollShopContext)) as MollShopContext; context.WriteLabourer(lab); return(RedirectToAction("Index", "Labourer")); }
/// <summary> /// Removes the received worker from the workers list. Returns false if the worker was not working this component. /// </summary> /// <param name="worker"></param> /// <returns></returns> public bool StoptWorking(Labourer worker) { if (IsLimited && _workers.Remove(worker)) { _currentWorkers = _workers.Count; return(true); } return(false); }
/// <summary> /// Add the recevied worker to the list of workers working this work component. Returns false if the work is already working this component or if the component cannot be worked. /// </summary> /// <param name="worker"></param> /// <returns></returns> public bool StartWorking(Labourer worker) { if (IsLimited && CanBeWorked && _workers.Add(worker)) { _currentWorkers = _workers.Count; return(true); } return(false); }
public override bool checkProceduralPrecondition(GameObject enemy) { wC = GetComponent <WorldCondition>(); lbr = GetComponent <Labourer> (); agent = GetComponent <NavMeshAgent>(); mts = GetComponent <menuju_tempat_sembunyi>(); // salah sasaran untuk index mis = GameObject.Find("enemy").GetComponent <misc> (); //timerM = lbr.timer; return(true); }
public override bool checkProceduralPrecondition(GameObject enemy) { lbr = GetComponent <Labourer> (); navComponent = GetComponent <NavMeshAgent> (); wC = GetComponent <WorldCondition> (); mis = GameObject.Find("enemy").GetComponent <misc> (); fs = GameObject.Find("player").GetComponent <FirstPersonController> (); timerM = 10f; target = mis.tempat_sembunyi [lbr.tampung].transform; wC.simpan = target; return(target != null); }
public int GetIdByRole(string userEmail, string role) { int id = 0; if (role.IndexOf("client", 0, StringComparison.CurrentCultureIgnoreCase) != -1) { var client = _context.Client.Where(c => c.ClientEmail == userEmail).FirstOrDefault(); id = client.ClientId; } else if (role.IndexOf("labourer", 0, StringComparison.CurrentCultureIgnoreCase) != -1) { Labourer labourer = _context.Labourer.Where(l => l.LabourerEmail == userEmail).FirstOrDefault(); id = labourer.LabourerId; } return(id); }
private static async Task CreateLabourer(string firstName, string lastName, string phone, string address, Weekdays availability, RecruitmentSystemContext context, UserManager <SystemUser> userManager, string role) { var email = firstName + "@" + lastName + ".com"; var user = await CreateUserWithRole(context, userManager, new SystemUser { Email = email, UserName = email }, role); var labourer = new Labourer { FirstName = firstName, LastName = lastName, Phone = phone, Address = address, City = "Vancouver", Province = "BC", Country = "Canada", IsActive = true, PersonalId = "123456789", User = user, Availability = availability }; context.Labourers.Add(labourer); //add skills var skills = context.Skills.ToList(); Random r = new Random(); var from = r.Next(0, 14); var to = r.Next(from, 14); var count = 1; for (var i = from; i <= to; i++) { if (count == 4) { break; } var labourerSkill = new LabourerSkill { Labourer = labourer, Skill = skills[i] }; context.LabourerSkills.Add(labourerSkill); count++; } context.SaveChanges(); }
public void TestAddNewLabourer() { DbConnector dbC = new DbConnector(); string resp = dbC.connect(); Assert.AreEqual("Done", resp); Labourer labrA = new Labourer(); labrA.Name = "Bob"; labrA.Age = 39; labrA.Gender = "male"; LabourerHandler labrHand = new LabourerHandler(); int resp2 = labrHand.addNewLabourer(dbC.getConn(), labrA); Assert.AreSame(1, resp2); }
public override bool checkProceduralPrecondition(GameObject agent) { lbr = GetComponent <Labourer> (); mts = GetComponent <menuju_tempat_sembunyi> (); navComponent = GetComponent <NavMeshAgent> (); mis = GameObject.Find("enemy").GetComponent <misc> (); //masalahnya disini lho // bagaimana cara memilih target yang tidak di tutup oleh player // kalau player ada didepan enemy maka target yang dipilih harus menjauh dari player tamp = Random.Range(0, mis.tempat_sembunyi.Length - 1); if (tamp >= lbr.tampung) { tamp += 1; } target = mis.tempat_sembunyi [tamp].transform; return(target != null); }
public void TestAddNewLabourer() { DBConnector dBc = new DBConnector(); string resp = dBc.connect(); Assert.AreEqual("Done", resp); Labourer labrA = new Labourer(); labrA.Name = "Bob"; labrA.Age = 39; labrA.Gender = "male"; LabourerHandler labrHand = new LabourerHandler(); int resp2 = labrHand.addNewLabourer(dBc.getConn(), labrA); Assert.IsNotNull(resp2); }
public async Task <LabourerVM> AddLabourer(LabourerVM labourerVM, string userId) { var labourer = new Labourer { UserId = userId, FirstName = labourerVM.FirstName, LastName = labourerVM.LastName, PersonalId = labourerVM.PersonalId, City = labourerVM.City, Province = labourerVM.Province, Country = labourerVM.Country, Address = labourerVM.Address, Phone = labourerVM.Phone, IsActive = labourerVM.IsActive, Availability = ConvertWeekdaysToEnum(labourerVM) }; _context.Add(labourer); var labourerSkills = new List <LabourerSkill>(); foreach (var skill in labourerVM.Skills) { var newSkill = new LabourerSkill { Labourer = labourer, SkillId = skill.Id.Value }; labourerSkills.Add(newSkill); _context.LabourerSkills.Add(newSkill); } labourer.LabourerSkills = labourerSkills; await UpdateUserEmail(userId, labourerVM.Email); _context.SaveChanges(); labourerVM.Id = labourer.Id; return(labourerVM); }
public IActionResult ToggleOnLeave(Labourer labourer) { var selectedLabourer = _context.Labourer.FirstOrDefault(l => l.LabourerId == labourer.LabourerId); if (selectedLabourer == null) { return(NotFound()); } else { selectedLabourer.OnLeave = labourer.OnLeave; if (labourer.OnLeave == true) { selectedLabourer.IsAvailable = false; } else { selectedLabourer.IsAvailable = true; } _context.SaveChanges(); } return(new ObjectResult(labourer)); }
}// intended private IEnumerator SpawnLaborer(Labourer lab) { IsBuilding = true; WhatsBeingBuild = lab; // wait the build time of the unit yield return(new WaitForSeconds(lab.BuildTime)); // spawn the new unit and puts it near your team supply depot. Max distant you are allowed to spawn is a 5 units radius from the supply position. var newLab = Instantiate(lab, LabourersParent, true); newLab.MyTeam = MyTeam; newLab.transform.position = transform.position + Vector3.forward * 3; SpawnedLaborers.Add(newLab); // pay the cost of the unit MySupplies.RemoveFireWood(lab.Costs[(int)Resources.Firewood], false); MySupplies.RemoveLogs(lab.Costs[(int)Resources.Log], false); MySupplies.RemoveOres(lab.Costs[(int)Resources.Ore], false); MySupplies.RemoveTools(lab.Costs[(int)Resources.Tools], false); IsBuilding = false; WhatsBeingBuild = null; }
string[] CreateGameState(Labourer[] agents, IDictionary<string, int> resources, IDictionary<string, int> buildings, string goal) { string[] resourcesStrings = { "stone", "coal", "ore", "iron", "timber", "wood", "money", "axes", "carts", "rifles" }; for (int i = 0; i < resources.Count; i++) { resourcesStrings[i] = "(= (" + resourcesStrings[i] + ") " + resources[resourcesStrings[i]] + ") "; } string[] buildingsStrings = { "huts", "houses", "schools", "barracks", "storages", "mines", "smelters", "quarries", "sawmills", "blacksmiths", "markets" }; for (int i = 0; i < buildings.Count; i++) { buildingsStrings[i] = "(= (" + buildingsStrings[i] + ") " + buildings[buildingsStrings[i]] + ") "; } string[] lines = new string[5]; lines [0] = "(define (problem task-problem)"; lines [1] = "(:domain task)"; string objectsLine = "(:objects "; for (int i = 0; i < agents.Length; i++) { objectsLine += agents[i].name + " "; } objectsLine += ")"; string initLine = "(:init "; for (int i = 0; i < agents.Length; i++) { if (agents[i].isPerson == true) initLine += "(isperson " + agents[i].name + ") "; if (agents[i].isLabourer == true) initLine += "(islabourer " + agents[i].name + ") "; if (agents[i].isCarpenter == true) initLine += "(iscarpenter " + agents[i].name + ") "; if (agents[i].isBlacksmith == true) initLine += "(isblacksmith " + agents[i].name + ") "; if (agents[i].isTeacher == true) initLine += "(isteacher " + agents[i].name + ") "; if (agents[i].isMiner == true) initLine += "(isminer " + agents[i].name + ") "; if (agents[i].isTrader == true) initLine += "(istrader " + agents[i].name + ") "; if (agents[i].isLumberjack == true) initLine += "(islumberjack " + agents[i].name + ") "; if (agents[i].isRifleman == true) initLine += "(isrifleman " + agents[i].name + ") "; if (agents[i].hasSkill == true) initLine += "(hasskill " + agents[i].name + ") "; if (agents[i].nearbyForest == true) initLine += "(nearbyforest " + agents[i].name + ") "; if (agents[i].nearbyStone == true) initLine += "(nearbystone " + agents[i].name + ") "; if (agents[i].nearbyOre == true) initLine += "(nearbyore " + agents[i].name + ") "; if (agents[i].nearbyCoal == true) initLine += "(nearbycoal " + agents[i].name + ") "; } for (int i = 0; i < resourcesStrings.Length; i++) { initLine += resourcesStrings[i]; } for (int i = 0; i < buildingsStrings.Length; i++) { initLine += buildingsStrings[i]; } initLine += "(= (people) " + agents.Length + ")"; initLine += ")"; string goalLine = "(:goal " + goal + ")" + ")"; lines [2] = objectsLine; lines [3] = initLine; lines [4] = goalLine; return lines; }
public async Task <JsonResult> OnPostAsync([FromBody] LabourerRegisterVM input) { var user = new IdentityUser { UserName = input.User.Email.ToLower(), Email = input.User.Email }; var result = await _userManager.CreateAsync(user, input.User.Password); var errorList = new List <string>(); dynamic jsonResponse = new JObject(); if (result.Succeeded) { SystemUser sysUser = new SystemUser() { Email = input.User.Email, Role = "Labourer" }; Labourer labourer = new Labourer { LabourerFirstName = input.Labourer.LabourerFirstName, LabourerLastName = input.Labourer.LabourerLastName, LabourerSin = input.Labourer.LabourerSin, LabourerEmail = input.User.Email, IsAvailable = true, OnLeave = false }; _context.SystemUser.Add(sysUser); sysUser.Labourer.Add(labourer); _context.SaveChanges(); //if (input.AvailableDays != null) //{ // foreach (string day in input.AvailableDays) // { // Availability availability = _context.Availability.Where(a => a.AvailabilityDay == day).FirstOrDefault(); // AvailabilityLabourer availabilityLabourer = new AvailabilityLabourer // { // AvailabilityId = availability.AvailabilityId, // LabourerId = labourer.LabourerId // }; // _context.AvailabilityLabourer.Add(availabilityLabourer); // _context.SaveChanges(); // } //} //else //{ // await _userManager.DeleteAsync(user); // _context.Labourer.Remove(labourer); // _context.SystemUser.Remove(sysUser); // _context.SaveChanges(); // jsonResponse.status = "Available day is not valid"; // jsonResponse.token = " "; // return Json(jsonResponse); //} foreach (int skillId in input.Skills) { LabourerSkill labourerSkill = new LabourerSkill { SkillId = skillId, LabourerId = labourer.LabourerId }; _context.LabourerSkill.Add(labourerSkill); _context.SaveChanges(); } AuthRepo registerRepo = new AuthRepo(_signInManager, _config, _serviceProvider, _context); var tokenString = registerRepo.GenerateJSONWebToken(user); jsonResponse.token = tokenString; jsonResponse.status = "OK"; jsonResponse.role = "Labourer"; jsonResponse.email = sysUser.Email; jsonResponse.id = labourer.LabourerId; jsonResponse.name = labourer.LabourerFirstName + ' ' + labourer.LabourerLastName; return(Json(jsonResponse)); } foreach (IdentityError error in result.Errors) { errorList.Add(error.Description); } jsonResponse.status = 422; jsonResponse.description = errorList[0]; jsonResponse.token = ""; return(Json(jsonResponse)); }
public void ParseCommands(string command) { IDictionary<string, int> resources = new Dictionary<string, int>(); IDictionary<string, int> buildings = new Dictionary<string, int>(); Labourer[] agents = new Labourer[8]; agents = Object.FindObjectsOfType<Labourer> (); // string goal = "(and (> (stone) 0) (> (iron) 0))"; resources = FillResourceValuesForTesting (resources); buildings = FillBuildingValuesForTesting (buildings); string parsedCommand = ""; bool suitableCommand = true; bool isGet = command.StartsWith ("get ", System.StringComparison.CurrentCultureIgnoreCase); bool isBuild = command.StartsWith ("build ", System.StringComparison.CurrentCultureIgnoreCase); bool isAttack = command.StartsWith ("attack ", System.StringComparison.CurrentCultureIgnoreCase); bool isMove = command.StartsWith ("move ", System.StringComparison.CurrentCultureIgnoreCase); bool isCraft = command.StartsWith ("craft ", System.StringComparison.CurrentCultureIgnoreCase); if (isGet == false && isBuild == false && isAttack == false && isMove == false) { suitableCommand = false; UnityEngine.Debug.Log("Command Failed."); } if (isGet == true) { int whichResource = 0; bool isStone = command.EndsWith (" stone", System.StringComparison.CurrentCultureIgnoreCase); bool isCoal = command.EndsWith (" coal", System.StringComparison.CurrentCultureIgnoreCase); if (isCoal == true) whichResource = 1; bool isOre = command.EndsWith (" ore", System.StringComparison.CurrentCultureIgnoreCase); if (isOre == true) whichResource = 2; bool isIron = command.EndsWith (" iron", System.StringComparison.CurrentCultureIgnoreCase); if (isIron == true) whichResource = 3; bool isTimber = command.EndsWith (" timber", System.StringComparison.CurrentCultureIgnoreCase); if (isTimber == true) whichResource = 4; bool isWood = command.EndsWith (" wood", System.StringComparison.CurrentCultureIgnoreCase); if (isWood == true) whichResource = 5; bool isMoney = command.EndsWith (" money", System.StringComparison.CurrentCultureIgnoreCase); if (isMoney == true) whichResource = 6; bool isAxe = command.EndsWith (" axe", System.StringComparison.CurrentCultureIgnoreCase); if (isAxe == true) whichResource = 7; bool isCart = command.EndsWith (" cart", System.StringComparison.CurrentCultureIgnoreCase); if (isCart == true) whichResource = 8; bool isRifle = command.EndsWith (" rifle", System.StringComparison.CurrentCultureIgnoreCase); if (isRifle == true) whichResource = 9; int howMany = 0; int first = command.IndexOf ("get ") + "get ".Length; int last = command.LastIndexOf(" "); int.TryParse(command.Substring(first, last - first), out howMany); switch(whichResource) { case 0: parsedCommand = "(> (stone) " + (howMany - 1) + ")"; break; case 1: parsedCommand = "(> (coal) " + (howMany - 1) + ")"; break; case 2: parsedCommand = "(> (ore) " + (howMany - 1) + ")"; break; case 3: parsedCommand = "(> (iron) " + (howMany - 1) + ")"; break; case 4: parsedCommand = "(> (timber) " + (howMany - 1) + ")"; break; case 5: parsedCommand = "(> (wood) " + (howMany - 1) + ")"; break; case 6: parsedCommand = "(> (money) " + (howMany - 1) + ")"; break; case 7: parsedCommand = "(> (axe) " + (howMany - 1) + ")"; break; case 8: parsedCommand = "(> (cart) " + (howMany - 1) + ")"; break; case 9: parsedCommand = "(> (rifle) " + (howMany - 1) + ")"; break; default: break; } } if (isBuild == true) { int whichBuilding = 0; bool isHut = command.EndsWith ("hut", System.StringComparison.CurrentCultureIgnoreCase); bool isHouse = command.EndsWith ("house", System.StringComparison.CurrentCultureIgnoreCase); if (isHouse == true) whichBuilding = 1; bool isSchool = command.EndsWith ("school", System.StringComparison.CurrentCultureIgnoreCase); if (isSchool == true) whichBuilding = 2; bool isBarracks = command.EndsWith ("barracks", System.StringComparison.CurrentCultureIgnoreCase); if (isBarracks == true) whichBuilding = 3; bool isStorage = command.EndsWith ("storage", System.StringComparison.CurrentCultureIgnoreCase); if (isStorage == true) whichBuilding = 4; bool isMine = command.EndsWith ("mine", System.StringComparison.CurrentCultureIgnoreCase); if (isMine == true) whichBuilding = 5; bool isSmelter = command.EndsWith ("smelter", System.StringComparison.CurrentCultureIgnoreCase); if (isSmelter == true) whichBuilding = 6; bool isQuarry = command.EndsWith ("quarry", System.StringComparison.CurrentCultureIgnoreCase); if (isQuarry == true) whichBuilding = 7; bool isSawmill = command.EndsWith ("sawmill", System.StringComparison.CurrentCultureIgnoreCase); if (isSawmill == true) whichBuilding = 8; bool isBlacksmith = command.EndsWith ("blacksmith", System.StringComparison.CurrentCultureIgnoreCase); if (isBlacksmith == true) whichBuilding = 9; bool isMarket = command.EndsWith ("market", System.StringComparison.CurrentCultureIgnoreCase); if (isMarket == true) whichBuilding = 10; switch(whichBuilding) { case 0: parsedCommand = "(> (huts) " + buildings["huts"] + ")"; break; case 1: parsedCommand = "(> (houses) " + buildings["houses"] + ")"; break; case 2: parsedCommand = "(> (schools) " + buildings["schools"] + ")"; break; case 3: parsedCommand = "(> (barracks) " + buildings["barracks"] + ")"; break; case 4: parsedCommand = "(> (storages) " + buildings["storages"] + ")"; break; case 5: parsedCommand = "(> (mines) " + buildings["mines"] + ")"; break; case 6: parsedCommand = "(> (smelters) " + buildings["smelters"] + ")"; break; case 7: parsedCommand = "(> (quarries) " + buildings["quarries"] + ")"; break; case 8: parsedCommand = "(> (sawmills) " + buildings["sawmills"] + ")"; break; case 9: parsedCommand = "(> (blacksmiths) " + buildings["blacksmiths"] + ")"; break; case 10: parsedCommand = "(> (markets) " + buildings["markets"] + ")"; break; default: break; } } if (suitableCommand == true) { goal = parsedCommand; string[] lines = CreateGameState (agents, resources, buildings, goal); WriteFile (lines); } }
protected override void Awake() { base.Awake(); _me = GetComponent <Labourer>(); }