public static void MessageSent(Human ambassador, Guid destination, string msg) { Kingdom k = FindKingdom(destination); HumanTask gettingBackTask = new HumanTask(ambassador) { TaskType = ETask.SendingMessage, Destination = k.UserId.ToString(), Context = Locale.Get("commands.send.empty_answer", k.Language) }; gettingBackTask.CalculateTaskTime(ambassador); ambassador.TasksToDo.AddRange(new[] { new HumanTask(ambassador) { TaskType = ETask.Waiting, TimeLeft = 3 }, gettingBackTask }); msg = string.Format(Locale.Get("commands.send.recieved", k.Language), ambassador.GetName(k.Language), k.Name, msg); UsersManager.Send(destination, new MessageCallback(msg)); }
public ExecutionResult Train(Dictionary <string, object> dict) { int count = 1; if (dict.ContainsKey("count")) { count = (int)dict["count"]; } if (!dict.ContainsKey("skill")) { return(new ExecutionResult(false, new MessageCallback(Locale.Get("jobs.no_job", this.Language), ECharacter.Knight))); } string sk = (string)dict["skill"]; JobDescription jb = ContentManager.GetJobDescriptionBySkill(sk); List <IDependency> deps = new List <IDependency>(jb.TrainDepence); deps.Add(new HumanDependency()); foreach (IDependency dep in deps) { Tuple <bool, MessageCallback> res = dep.CheckKingdom(this); if (!res.Item1) { return(new ExecutionResult(false, res.Item2)); } } Human h = dict.Get("human") as Human ?? FindBySkill(sk, false); HumanTask task = new HumanTask(h) { Destination = sk, TaskType = ETask.Training }; task.CalculateTaskTime(h); if (!h.AddTask(task)) { return(new ExecutionResult(false, new MessageCallback( Locale.Get(string.Format("problems.dont_work", h.GetName(Language)), Language), ECharacter.Knight ))); } else { return(new ExecutionResult(new MessageCallback(Locale.Get("answers.yes", this.Language)))); } }
public ExecutionResult Extract(Dictionary <string, object> dict) { if (!dict.ContainsKey("resource")) { return(new ExecutionResult(false, new MessageCallback(Locale.Get("resources.no_resource", this.Language), ECharacter.Knight))); } ItemDescription r = (ItemDescription)dict["resource"]; foreach (IDependency dep in r.ExtractionDependencies) { Tuple <bool, MessageCallback> res = dep.CheckKingdom(this); if (!res.Item1) { return(new ExecutionResult(false, res.Item2)); } } Human h = dict.Get("human") as Human ?? FindBySkill(r.Skill); HumanTask t = new HumanTask(h) { Destination = r.Name, TaskType = ETask.Extracting, Repeating = true }; t.CalculateTaskTime(h, r.Difficulty, r.Skill); foreach (IDependency dep in r.ExtractionDependencies) { t.Use(dep.Use(this)); } if (!h.AddTask(t)) { return(new ExecutionResult(false, new MessageCallback( Locale.Get(string.Format("problems.dont_work", h.GetName(Language)), Language), ECharacter.Knight ))); } else { return(new ExecutionResult(new MessageCallback(Locale.Get("answers.yes", this.Language)))); } }
public ExecutionResult Build(Dictionary <string, object> dict) { if (!dict.ContainsKey("building")) { return(new ExecutionResult(false, new MessageCallback(Locale.Get("buildings.no_building", this.Language), ECharacter.Knight))); } BuildingDescription b = (BuildingDescription)dict["building"]; foreach (IDependency dep in b.Dependencies) { Tuple <bool, MessageCallback> res = dep.CheckKingdom(this); if (!res.Item1) { return(new ExecutionResult(false, res.Item2)); } } Human h = dict.Get("human") as Human ?? FindBySkill("building"); HumanTask t = new HumanTask(h); t.Destination = b.Name; t.TaskType = ETask.Building; foreach (IDependency dep in b.Dependencies) { t.Use(dep.Use(this)); } t.CalculateTaskTime(h); if (!h.AddTask(t)) { return(new ExecutionResult(false, new MessageCallback( Locale.Get(string.Format("problems.dont_work", h.GetName(Language)), Language), ECharacter.Knight ))); } else { return(new ExecutionResult(new MessageCallback(Locale.Get("answers.yes", this.Language)))); } }
private MessageCallback[] WorkTasks(Human h, float delta) { List <MessageCallback> res = new List <MessageCallback>(); HumanTask t = h.TasksToDo.FirstOrDefault(); while (t != null) { if (t.TaskType != ETask.ListeningKing) { t.TimeLeft -= delta; } int k = h.Worked(delta, t.Difficulty) ? 1 : -1; var soworkers = new List <Human>(); for (int i = 0; i < t.InUse.Count; ++i) { Guid[] owners_ids = t.InUse[i].GetOwners(); for (int j = 0; j < owners_ids.Length; ++j) { h.UpdateFriendship(owners_ids[j], k * delta); } } if (t.TimeLeft <= 0) { if (t.Skill != null) { h.UpgradeSkill(t.Skill, 0.999f); } h.TasksToDo.RemoveAt(0); delta = delta + t.TimeLeft; if (t.Repeating) { t.CalculateTaskTime(h, t.Difficulty, t.Skill); if (!h.AddTask(t)) { res.Add(new MessageCallback( Locale.Get(string.Format("problems.dont_work", h.GetName(Language)), Language), ECharacter.Knight )); } } switch (t.TaskType) { case ETask.Building: AddBuilding(t.Destination, h.GetSkill("building")); string bname = ContentManager.GetBuildingName(t.Destination, Language); string msg = string.Format(Locale.Get("notifications.builded", Language), bname); res.Add(new MessageCallback(msg, ECharacter.King)); break; case ETask.Training: h.UpgradeSkill(t.Destination); break; case ETask.Extracting: case ETask.Creating: AddResource(t.Destination, 1, h.GetSkill(t.Skill)); break; } t = h.TasksToDo.FirstOrDefault(); } else { break; } } return(res.ToArray()); }