//可以增加或者删除物品(count是负数的时候),添加物品的时候可以在数量后面加"xxAttr1:4,xxAttr2:5"添加该物品的附加属性 public bool DealItems(Dictionary <string, string> itemDict, DoerAttrParser doerAttrParser = null) { doerAttrParser = doerAttrParser ?? new DoerAttrParser(this); foreach (var itemId in itemDict.Keys) { string value = itemDict[itemId]; Hashtable addAttrDict = new Hashtable(); //带属性 int pos = value.IndexOf("("); if (pos != -1) { string attrString = value.Substring(pos + 1, value.Length - pos - 2); //最后一个)也要删除 value = value.Substring(0, pos); addAttrDict = attrString.ToDictionary <string, string>().ToHashtable(); } int count = doerAttrParser.ParseInt(value); if (count < 0) //remove Items { count = Math.Abs(count); Item[] items = this.RemoveItems(itemId, count); for (var i = 0; i < items.Length; i++) { var item = items[i]; item.Destruct(); } } else //add Items { Item item = Client.instance.itemFactory.NewDoer(itemId) as Item; for (int i = 0; i < count; i++) { if (!addAttrDict.IsNullOrEmpty()) { var list = new ArrayList(addAttrDict.Keys); for (var j = 0; j < list.Count; j++) { var attrName = (string)list[j]; addAttrDict[attrName] = doerAttrParser.Parse(addAttrDict[attrName] as string); } item.AddAll(addAttrDict); } bool isCanFold = item.CanFold(); if (isCanFold) { item.SetCount(count); this.AddItem(item); break; } this.AddItem(item); } } } return(true); }
public DoerAttrSetter(string desc = null, DoerAttrParser doerAttrParser = null) { SetDesc(desc); if (doerAttrParser != null) { SetU(doerAttrParser.GetU()); SetO(doerAttrParser.GetO()); SetE(doerAttrParser.GetE()); SetM(doerAttrParser.GetM()); SetDoerAttrParser(doerAttrParser); } }
public bool CheckFinishCondition() { string finishCondition = this.GetCfgMissionData().finish_condition; if (!finishCondition.IsNullOrWhiteSpace()) // 未设置完成条件的办事任务不能根据派发任务处来完成,只能在设置了可完成任务的时候检测是否就绪 { DoerAttrParser doerAttrParser = new DoerAttrParser(Client.instance.user, this, this.GetOwner()); if (doerAttrParser.ParseBoolean(finishCondition, false)) { return(true); } } return(false); }
////////////////////////////////////////////////////////////////////////// //owner 发放任务的npc public virtual bool Execute(string desc, Doer owner, DoerAttrParser doerAttrParser) { if (!CheckDoerEventTriggerCondition(doerAttrParser)) { return(false); } var cfgDoerEventData = GetCfgDoerEventData(); bool isNotTalk = cfgDoerEventData.is_not_talk; // 不弹出talk //通用情况 string triggerDesc = cfgDoerEventData.trigger_desc; List <string> wordList = new List <string>(); if (!triggerDesc.IsNullOrWhiteSpace()) { wordList.Add(doerAttrParser.ParseString(triggerDesc)); } int ok = 1; // 0-触发条件失败,1-触发成功,执行失败,2-触发成功,执行成功 string[] stepIds = cfgDoerEventData._step_ids; if (!stepIds.IsNullOrEmpty()) { for (int i = 0; i < stepIds.Length; i++) { string stepId = stepIds[i]; var cfgDoerEventStep = CfgDoerEventStep.Instance.get_by_id(stepId); ok = ExecuteStep(desc + "步骤" + (i + 1), stepId, owner, doerAttrParser, wordList); if (ok == 0) { break; } if (ok == 2 && cfgDoerEventStep.is_stop_here) { break; } } } if (!isNotTalk && wordList.Count > 0) { for (var i = 0; i < wordList.Count; i++) { var word = wordList[i]; Client.instance.uiManager.Notify(word); } } return(ok > 0); }
public Dictionary <string, int> GetRewards(DoerAttrParser doerAttrParser) { Dictionary <string, int> result = new Dictionary <string, int>(); Dictionary <string, string> rewardDict = GetCfgMissionData()._reward_dict; if (!rewardDict.IsNullOrEmpty()) { foreach (string itemId in rewardDict.Keys) { string curItemId = doerAttrParser.ParseString(itemId); string countString = rewardDict[itemId]; int count = doerAttrParser.ParseInt(countString); result[curItemId] = count; } } return(result); }
public override bool OnAccept(User user) { if (!base.OnAccept(user)) { return(false); } DoerAttrParser doerAttrParser = new DoerAttrParser(Client.instance.user, this, this.GetOwner(), null); Dictionary <string, string> findItemDict = GetCfgMissionData()._find_item_dict; Dictionary <string, int> curFindItemDict = new Dictionary <string, int>(); foreach (var itemId in findItemDict.Keys) { string itemCountString = findItemDict[itemId]; int itemCount = doerAttrParser.ParseInt(itemCountString, 0); curFindItemDict[itemId] = itemCount; } this.Set("find_item_dict", curFindItemDict); return(true); }
public bool CheckDoerEventTriggerCondition(DoerAttrParser doerAttrParser) { var cfgDoerEventData = CfgDoerEvent.Instance.get_by_id(this.GetId()); bool isNotTalk = cfgDoerEventData.is_not_talk; // 不弹出talk string triggerCondition = cfgDoerEventData.trigger_condition; // 触发条件 if (!triggerCondition.IsNullOrWhiteSpace() && !doerAttrParser.ParseBoolean(triggerCondition)) //不满足触发的情况 { if (!isNotTalk) { string canNotTriggerDesc = cfgDoerEventData.can_not_trigger_desc; Client.instance.uiManager.Notify(canNotTriggerDesc.IsNullOrWhiteSpace() ? Lang.GetText("现在不能触发此操作") : doerAttrParser.ParseString(canNotTriggerDesc)); } return(false); } return(true); }
public bool GetDoerValue_Doer(Doer doer, string key, string type_string, out string result) { bool isBreak = false; result = null; if (doer is Doer) { if (key.StartsWith(StringConst.String_env_dot) || key.StartsWith(StringConst.String_envt_dot)) { Doer env = doer.GetEnv(); if (env != null) { key = key.Substring(StringConst.String_env.Length); DoerAttrParser doerAttrParser = new DoerAttrParser(env); result = doerAttrParser.ParseString(type_string + StringConst.String_u + key); return(true); } result = ConvertValue(StringConst.String_Empty, type_string); return(true); } if (key.StartsWith(StringConst.String_pos2)) { key = key.Substring(StringConst.String_pos2.Length); Vector2 pos2 = doer.GetPos2(); if (pos2 != Vector2Const.Default) { if (key.Equals(StringConst.String_dot_x)) { result = ConvertValue(pos2.x, type_string); return(true); } if (key.Equals(StringConst.String_dot_y)) { result = ConvertValue(pos2.y, type_string); return(true); } result = ConvertValue(pos2.ToString(), type_string); return(true); } result = ConvertValue(StringConst.String_Empty, type_string); return(true); } if (key.StartsWith(StringConst.String_pos3)) { key = key.Substring(StringConst.String_pos3.Length); Vector3 pos3 = doer.GetPos3(); if (pos3 != Vector3Const.Default) { if (key.Equals(StringConst.String_dot_x)) { result = ConvertValue(pos3.x, type_string); return(true); } if (key.Equals(StringConst.String_dot_y)) { result = ConvertValue(pos3.y, type_string); return(true); } if (key.Equals(StringConst.String_dot_z)) { result = ConvertValue(pos3.z, type_string); return(true); } result = ConvertValue(pos3.ToString(), type_string); return(true); } result = ConvertValue(StringConst.String_Empty, type_string); return(true); } } return(isBreak); }
//owner 发放任务的npc public int ExecuteStep(string desc, string doerEventStepId, Doer owner, DoerAttrParser doerAttrParser, List <string> wordList) { var cfgDoerEventStepData = CfgDoerEventStep.Instance.get_by_id(doerEventStepId); string triggerCondition = cfgDoerEventStepData.trigger_condition; // 触发条件 if (!triggerCondition.IsNullOrWhiteSpace() && !doerAttrParser.ParseBoolean(triggerCondition)) //不满足触发的情况 { string canNotTriggerDesc = cfgDoerEventStepData.can_not_trigger_desc; wordList.Add(canNotTriggerDesc.IsNullOrWhiteSpace() ? Lang.GetText("现在不能触发此操作") : doerAttrParser.ParseString(canNotTriggerDesc)); return(0); } string triggerDesc = cfgDoerEventStepData.trigger_desc; // 触发提示语 if (!triggerDesc.IsNullOrWhiteSpace()) { wordList.Add(doerAttrParser.ParseString(triggerDesc)); } string executeCondition = cfgDoerEventStepData.execute_condition; // 执行条件 if (!executeCondition.IsNullOrWhiteSpace() && !doerAttrParser.ParseBoolean(executeCondition)) //不满足执行条件的情况 { string canNotExecuteDesc = cfgDoerEventStepData.can_not_execute_desc; // 不执行提示语 if (!canNotExecuteDesc.IsNullOrWhiteSpace()) { wordList.Add(doerAttrParser.ParseString(canNotExecuteDesc)); } return(1); } string executeDesc = cfgDoerEventStepData.execute_desc; // 执行提示语 if (!executeDesc.IsNullOrWhiteSpace()) { wordList.Add(doerAttrParser.ParseString(executeDesc)); } DoerAttrSetter doerAttrSetter = new DoerAttrSetter(desc, doerAttrParser); //设置属性、更改属性 Dictionary <string, string> setAttrDict = cfgDoerEventStepData._set_attr_dict; foreach (var attrName in setAttrDict.Keys) { doerAttrSetter.Set(attrName, setAttrDict[attrName], false); } Dictionary <string, string> addAttrDict = cfgDoerEventStepData._add_attr_dict; foreach (var attrName in addAttrDict.Keys) { doerAttrSetter.Set(attrName, addAttrDict[attrName], true); } User user = null; if (doerAttrParser.GetU() is User) { user = (User)doerAttrParser.GetU(); } else if (doerAttrParser.GetO() is User) { user = (User)doerAttrParser.GetO(); } else if (doerAttrParser.GetE() is User) { user = (User)doerAttrParser.GetE(); } else { user = Client.instance.user; } //添加或者删除物品 Dictionary <string, string> dealItemDict = cfgDoerEventStepData._deal_item_dict; if (!dealItemDict.IsNullOrEmpty()) { user.DealItems(dealItemDict, doerAttrParser); } // 接受任务 string[] accept_mission_ids = cfgDoerEventStepData._accept_mission_ids; foreach (var accept_mission_id in accept_mission_ids) { user.AcceptMission(accept_mission_id, owner); } // 完成任务 string[] finishMissionIds = cfgDoerEventStepData._finish_mission_ids; for (var i = 0; i < finishMissionIds.Length; i++) { var finishMissionId = finishMissionIds[i]; user.FinishMission(finishMissionId, owner); } // 放弃任务 string[] giveUpMissionIds = cfgDoerEventStepData._give_up_mission_ids; for (var i = 0; i < giveUpMissionIds.Length; i++) { var giveUpMissionId = giveUpMissionIds[i]; user.GiveUpMission(giveUpMissionId, owner); } // 添加已完成任务 string[] addFinishedMissionIds = cfgDoerEventStepData._add_finished_mission_ids; for (var i = 0; i < addFinishedMissionIds.Length; i++) { var addFinishedMissionId = addFinishedMissionIds[i]; user.AddFinishedMissionId(addFinishedMissionId); } // 删除已完成任务 string[] removeFinishedMissionIds = cfgDoerEventStepData._remove_finished_mission_ids; for (var i = 0; i < removeFinishedMissionIds.Length; i++) { var removeFinishedMissionId = removeFinishedMissionIds[i]; user.RemoveFinishedMissionId(removeFinishedMissionId); } // 检测完成任务 user.CheckAutoFinishMissions(); return(2); }
public void SetDoerAttrParser(DoerAttrParser doerAttrParser) { this.doerAttrParser = doerAttrParser; }