每一个客户端进入主城,都会有一个个人的任务数据,任务数据通过配置文件读取,任务进度则需要通过服务端存储。

任务数据

下面是一个任务数据xml:

ID表示任务号,是用来读取任务数据和存储任务进度的关键。

npcID表示这个任务需要对话的npc

dilogArr表示对话内容

actID表示角色动作的ID

coin和exp表示完成任务的奖励。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<item ID="1001">
<npcID>0</npcID>
<dilogArr>#0|智者您好,晚辈$name,前来拜会。
#1|漫漫人生路,你我得以相遇也是一种缘分。我看你骨骼精奇,眉宇间正气凛然,将来定能成就一番事业。
#0|智者过誉了,晚辈阅历尚浅,学识浅薄,空有满腔热血,还请前辈多多教导。
#1|教导谈不上,但我现有一事可交付与你,若你能办妥,对你而言也是一种历练。你可有意为之?
#0|能为智者办事,是晚辈的福分,定当竭尽所能,请您明示。
#1|甚好,此事我已安排妥当,你去主城找凯伦将军,他会告诉你怎么做。
#0|好的,晚辈即刻启程。
</dilogArr>
<actID>0</actID>
<coin>65</coin>
<exp>80</exp>
</item>
<item ID="1002">
<npcID>1</npcID>
<dilogArr>#0|将军,晚辈$name,乃智者派遣前来,说有一事交付于我。
#1|你终于来了,我已经在此地等候多时了。智者果然没有看错人。
#0|全凭智者提携晚辈,才有机会谋得此事。定当竭尽所能,以尽绵薄之力。
#1|距离此地10里荒原之处,常有兽匪出没,滋扰边境,现派你去侦察敌情,以便大军及时过境。
#0|请将军放心,我即刻出发,尽快查实情况。
</dilogArr>
<actID>1</actID>
<coin>75</coin>
<exp>90</exp>
</item>
<item ID="1003">
<npcID>2</npcID>
<dilogArr>#0|老板,你好,我需要对自己的装备进行修复更新。请问你能帮我吗?
#1|少侠好眼力,我是全城最好的工匠,没有之一。你来找我算是来对地方了。
#0|甚好甚好,那就麻烦你了。
#1|不麻烦,你只要有钱就行了。谁也不会和钱过不去,对么?
</dilogArr>
<actID>2</actID>
<coin>85</coin>
<exp>100</exp>
</item>
<item ID="1004">
<npcID>3</npcID>
<dilogArr>#1|江湖路漫漫,耗神又费力,你需要补充一些体力了。
#0|休息是为了走更远的路,翻越更高的山,我需要补充一些体力了。</dilogArr>
<actID>3</actID>
<coin>95</coin>
<exp>110</exp>
</item>
<item ID="1005">
<npcID>-1</npcID>
<dilogArr>#1|钱不是万能的,但没钱是万万不能的。
#0|是时候让自己的口袋更充实一些了。</dilogArr>
<actID>4</actID>
<coin>105</coin>
<exp>120</exp>
</item>
<item ID="1006">
<npcID>-1</npcID>
<dilogArr>#1|沟通能接近彼此之间的距离。但如果没能拉近,肯定是你没有说普通话。
#0|是时候让世界听到我的声音了。</dilogArr>
<actID>5</actID>
<coin>115</coin>
<exp>130</exp>
</item>
</root>

读取任务数据

凡是配置数据,都从ResSvc当中读取

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#region 自动引导配置
private Dictionary<int,AutoGuideCfg> guideCfgDataDic = new Dictionary<int,AutoGuideCfg>();
private void InitGuideCfg(string path)
{
TextAsset guideCfgAsset = Resources.Load<TextAsset>(path);
if(guideCfgAsset != null )
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(guideCfgAsset.text);

XmlNodeList xmlNodeList = xmlDoc.SelectSingleNode("root").ChildNodes;
for(int i = 0; i < xmlNodeList.Count; i++)
{
XmlElement ele = xmlNodeList[i] as XmlElement;
if(ele.GetAttributeNode("ID") == null)
{
continue;
}
int ID = Convert.ToInt32(ele.GetAttributeNode("ID").InnerText);

AutoGuideCfg autoGuideCfg = new AutoGuideCfg { ID = ID };

foreach(XmlElement element in ele.ChildNodes)
{
switch(element.Name)
{
case "npcID":
autoGuideCfg.npcID = int.Parse(element.InnerText);
break;
case "dilogArr":
autoGuideCfg.dilogArr = element.InnerText;
break;
case "actID":
autoGuideCfg.actID = int.Parse(element.InnerText);
break;
case "coin":
autoGuideCfg.coin = int.Parse(element.InnerText);
break;
case "exp":
autoGuideCfg.exp = int.Parse(element.InnerText);
break;
}
}
guideCfgDataDic.Add(ID, autoGuideCfg);
}
}
}

public AutoGuideCfg GetAutoGuideData(int ID)
{
AutoGuideCfg autoGuideCfg = null;
if (guideCfgDataDic.TryGetValue(ID, out autoGuideCfg))
{
return autoGuideCfg;
};
return null;
}
#endregion

应用任务数据

首先在MainCityWnd当中应用任务数据,用来刷新自动引导按钮显示的头像图标:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
AutoGuideCfg curTaskData;

private void RefreshUI()
{
//...
//设置自动任务图标
curTaskData = resSvc.GetAutoGuideData(playerData.guideid);//数据库中存储guideid进度
if(curTaskData != null)
{
SetGuideButton(curTaskData.npcID);
}
else
{
SetGuideButton(-1);
}
}
private void SetGuideButton(int npcID)
{
string spPath = "";
Image img = btnGuide.GetComponent<Image>();
switch(npcID)
{

case Constants.NPCWiseMan://每个NPC代表的数字也要配置好
spPath = PathDefine.WiseManHead;
break;
case Constants.NPCGeneral:
spPath = PathDefine.GeneralHead;
break;
case Constants.NPCArtisan:
spPath = PathDefine.ArtisanHead;
break;
case Constants.NPCTrader:
spPath = PathDefine.TraderHead;
break;
default:
spPath = PathDefine.TaskHead;
break;
}
SetSprite(img, spPath);//WindowRoot封装的方法
}

private void ClickGuideBtn()//给GuideBtn监听的方法
{
audioSvc.PlayUIAudio(Constants.UIClickBtn);
if(curTaskData != null)
{
MainCitySys.Instance.RunTask(curTaskData);//在MainCitySystem处理具体任务逻辑
}
else
{
GameRoot.AddTips("More Guide Missions are under developing......");
}
}