Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 14.04.2006, 06:55   #1
Digital
Архивный участник
 
Join Date: Nov 2004
Posts: 1,405
Default [Tutorial] AI Tutorial - Included SP1-3 [Chinese]

from 99nets

说明:由于本人时间不多(本科在读� �,所以可能出的比较慢,但是我会陆� ��共享出ai的秘密。再次向

各位前辈以及共享的同志致敬!

AI教程--SP1 AI在天堂脚本中的地位

AI全称是人工智能,在天堂教本中发挥 着协助主程序控制游戏内部事件的作� �。

我只所以叫AI而不叫ai.obj,这个是因为 ai.obj和script中的其他教本结合起来才� �AI,ai.obj的函数定

义被封装在主程序,而协导的是txt教� �。可以说一个完成的script加对应的htm� ��成天堂的AI系统。

举个例子,比如怪物的攻击行为,控� �怪物行为是在ai.obj中完成,在怪物请� ��魔法攻击的时候,ai调用

skilldata中的对应技能才能完成。

sp1知识点:
一个完成ai的结构形式

class 类名 : 父类
//定义成员变量
parameter_define_begin
数据类型 变量名 变量初始值
...
parameter_define_end

//成员函数,主要是响应各种事件
handler 事件号
variable_begin
事件参数,根据不用的事件而不同。
...
variable_end

代码
...
handler_end

...

class_end

eg:
class default_npc : (null)
parameter_define_begin
int DesirePqSize 50
int FavorListSize 30
float IdleDesire_DecayRatio 0.000000
float MoveAround_DecayRatio 0.000000
float DoNothing_DecayRatio 0.000000
float Attack_DecayRatio 0.000000
float Chase_DecayRatio 0.000000
float Flee_DecayRatio 0.000000
float GetItem_DecayRatio 0.000000
float Follow_DecayRatio 0.000000
float Decaying_DecayRatio 0.000000
float MoveToWayPoint_DecayRatio 0.000000
float UseSkill_DecayRatio 0.000000
float MoveTo_DecayRatio 0.000000
float EffectAction_DecayRatio 0.000000
float IdleDesire_BoostValue 0.000000
float MoveAround_BoostValue 0.000000
float DoNothing_BoostValue 0.000000
float Attack_BoostValue 0.000000
float Chase_BoostValue 0.000000
float Flee_BoostValue 0.000000
float GetItem_BoostValue 0.000000
float Follow_BoostValue 0.000000
float Decaying_BoostValue 0.000000
float MoveToWayPoint_BoostValue 0.000000
float UseSkill_BoostValue 0.000000
float MoveTo_BoostValue 0.000000
float EffectAction_BoostValue 0.000000
parameter_define_end
handler 0 // NO_DESIRE
variable_begin
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end

handler_end

handler 4 // TALK_SELECTED
variable_begin
"talker"
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end

shift_sp 1
push_event // talker
push_const 32
add
fetch_i
S0. "noquest.htm"
push_string S0
func_call 43 // func[ShowPage]
shift_sp -2
shift_sp -1
handler_end

class_end


AI教程--SP2 AI的结构以及NPCdata对ai的调用
AI的结构类似于C++中的类与继承,下面 介绍下ai中的类。
首先说下类的特点:子类可以完全继承� ��类,也可以对父类进行追加操作。
在天堂的ai中类的关系如下:
default_npc
-warrior各种狩猎怪物
-citizen guard guild_master guild_coach warehouse_keeper merchant merchant_for_cgrade castle_merchant teleporter instant_teleporter siege_instant_teleporter castle_instant_teleporter delayed_teleporter chamberlain steward ordery chief_royal_guard doorkeeper house_master custodian agit_in auction_dealer各种对话行为NPC
-summon_heal summon_magicalattack summon_physicalattack summon_siege_golem pet_physicalattack pet_use_one_skill各种召唤兽控制行为
大家不必看着上面这些头疼,自己细� �的话可以找出这些NPC的ai代码段,即� �自己看不懂代码,但是只要明白它的� ��能,那么我们如果要添加一个NPC,只 要找到相同行为的类,在npcdata里面直� ��饮用就可以了。
eg1:
添加了圣诞树,我们拟定它只是一个� �体,不提供任何功能,那么我们可以� ��么写它的npcdata里面的ai引用:
npc_ai={[default_npc]}
或者这样写:
在npcdata里面写npc_ai={[x_mas_tree]},在ai.obj里面添加如下代码段:
class x_mas_tree : default_npc
class_end
如上思路,我们要让它成为一个传送师� ��话,可以这样写:
npcdata对ai直接引用法:
npc_ai={[teleporter]}
或者这样写:
在npcdata里面写npc_ai={[x_mas_tree]},在ai.obj里面添加如下代码段:
class x_mas_tree : teleporter
class_end
注意:
1.自己使用npcdata直接引用法引用的ai在 ai.obj里面要存在.
2.npcdata和ai.obj结合法引用的ai要存在自 己的父类,而且ai里面添加的代码一定� �在自己父类的顺序的下面.比如如下代 码就是错误的:
class x_mas_tree : teleporter
class_end
class teleporter : default_npc
...
class_end
3.别忘记在sp1里面说的,要结合htm文件,� ��格意义上的替换,这里我举个例子大� �要绝对认真看
eg2:
比如我们要用npcdata直接引用法让x_mas_t ree的行为跟rapunzel的行为一样.我们第� �步要找到npcdata里面rapunzel这个怪的ai� �用方式,看是直接引用还是加变量付值 引用.我们查找到的ai引用如下
npc_ai={[rapunzel];{[fnHi] = [rapunzel001.htm]};{[fnYouAreChaotic] = [rapunzel003.htm]}}
这就说明这个怪的ai引用方式是变量负 值引用,那么就说明了在ai.obj里面用到� ��fnHi和fnYouAreChaotic这两个变量,而且这� ��个变量的负值行为发生在npcdata里面,� ��么我们就要在引用ai的同时,也要考虑 变量了.注意:这里的两个变量的值是两 个htm文件,我们要在htm文件夹下找到这� ��个文件,打开,修改对话内容(要是纯文 本内容的话,自己随便修改,要是出现<a action=.../a>字段,那么我们千万不要动这段代码,� ��为在ai里面的对应事件以及id要和字� �里面的相同,不然会发生严重错误.具� �要怎么修改,我以后会谈到),修改好的� ��件,比如第一个叫ask1.htm,第二个叫ask2. htm,那么我们可以这样引用这样修改:
npc_ai={[rapunzel];{[fnHi] = [ask1.htm]};{[fnYouAreChaotic] = [ask2.htm]}}
也可以这样修改
npc_ai={[x_mas_tree]}
在ai.obj里面添加如下代码
class x_mas_tree : rapunzel
parameter_define_begin
string fnHi "ask1.htm"
string fnYouAreChaotic "ask2.htm"
parameter_define_end
class_end

小结:本部分主要介绍了一个直接引用� ��,可以解决大多数简单NPC行为引用,一� ��GM学到此就可以了.要想深入学习ai,掌 握独立开发编写ai的能力,请关注以后 的内容.

AI教程--SP3 AI对事件的控制过程


前面我介绍了AI的基础知识以及最简单 的修改办法,从这部分开始,我将介� �AI的实际工作方法以及自己编写ai脚本 的方法。
首先介绍一下ai的handler。
在目前的ai里面,我们能提取出63个hand ler。那么handler起什么用呢?我们通过� ��析一个完整ai的结构可以发现,一个
handler_begin ID
...
handler_end
所代表是一个事件的控制方法,它是� �堂中人工智能的事件管理者。
每一个hadler的ID代表的事件是不同的, 从逻辑上说独立事件不可能在逻辑上� �时进行另外的事件,所以一个handler结 构内只能使用各种函数进行控制操作� �不能再引用别的handler。
比如如下的handler结构就是错误的
handler_begin ID1
...
handler_begin ID2
...
handler_end
...
handler_end
下面我公布ai中的63个handler以及代表的 处理事件
handler 0 // NO_DESIRE
handler 1 // ATTACKED
handler 2 // SPELLED
handler 3 // TALKED
handler 4 // TALK_SELECTED
handler 5 // SEE_CREATURE
handler 10 // MY_DYING
handler 11 // TIMER_FIRED
handler 12 // TIMER_FIRED_EX
handler 13 // CREATED
handler 16 // SEE_SPELL
handler 17 // OUT_OF_TERRITORY
handler 18 // DESIRE_MANIPULATION
handler 19 // PARTY_ATTACKED
handler 21 // PARTY_DIED
handler 23 // CLAN_ATTACKED
handler 25 // STATIC_OBJECT_CLAN_ATTACKED
handler 28 // TELEPORT_REQUESTED
handler 31 // QUEST_ACCEPTED
handler 32 // MENU_SELECTED
handler 33 // LEARN_SKILL_REQUESTED
handler 34 // ONE_SKILL_SELECTED
handler 36 // CLASS_CHANGE_REQUESTED
handler 42 // CREATE_PLEDGE
handler 43 // DISMISS_PLEDGE
handler 44 // REVIVE_PLEDGE
handler 45 // LEVEL_UP_PLEDGE
handler 48 // CREATE_ALLIANCE
handler 49 // SCRIPT_EVENT
handler 50 // TUTORIAL_EVENT
handler 51 // QUESTION_MARK_CLICKED
handler 52 // USER_CONNECTED
handler 61 // MOVE_TO_WAY_POINT_FINISHED
handler 62 // USE_SKILL_FINISHED
handler 63 // MOVE_TO_FINISHED
handler中可以使用的函数(204个):
func_call 0 // func[AddMoveAroundDesire]
func_call 1 // func[AddDoNothingDesire]
func_call 2 // func[AddAttackDesire]
func_call 3 // func[AddAttackDesireEx]
func_call 6 // func[AddFleeDesire]
func_call 7 // func[AddFollowDesire]
func_call 9 // func[AddMoveToWayPointDesire]
func_call 10 // func[AddUseSkillDesire]
func_call 11 // func[AddUseSkillDesireEx]
func_call 12 // func[AddMoveToDesire]
func_call 13 // func[AddEffectActionDesire]
func_call 14 // func[AddPetDefaultDesire_Follow]
func_call 15 // func[RemoveAllAttackDesire]
func_call 18 // func[MakeAttackEvent]
func_call 20 // func[GetLifeTime]
func_call 21 // func[GetTick]
func_call 23 // func[GetCurrentTick]
func_call 24 // func[GetDirection]
func_call 25 // func[SetCookie]
func_call 26 // func[GetCookie]
func_call 27 // func[SetTeleportPosOnLost]
func_call 28 // func[AddTimerEx]
func_call 29 // func[GetIndexFromCreature]
func_call 30 // func[GetCreatureFromIndex]
func_call 31 // func[RegisterGlobalMap]
func_call 32 // func[UnregisterGlobalMap]
func_call 33 // func[GetGlobalMap]
func_call 34 // func[SendScriptEvent]
func_call 36 // func[IsSpoiled]
func_call 37 // func[Say]
func_call 42 // func[Shout]
func_call 43 // func[ShowPage]
func_call 45 // func[Teleport]
func_call 46 // func[InstantTeleport]
func_call 47 // func[Sell]
func_call 48 // func[Buy]
func_call 51 // func[DistFromMe]
func_call 52 // func[SetTimerPeriodByTick]
func_call 53 // func[SetTimerPeriod]
func_call 54 // func[GetWayPointDelay]
func_call 55 // func[Rand]
func_call 57 // func[FloatToInt]
func_call 58 // func[GetMemoCount]
func_call 59 // func[HaveMemo]
func_call 60 // func[SetMemo]
func_call 61 // func[SetMemoState]
func_call 62 // func[GetMemoState]
func_call 63 // func[RemoveMemo]
func_call 64 // func[SetJournal]
func_call 65 // func[GetOneTimeQuestFlag]
func_call 66 // func[SetOneTimeQuestFlag]
func_call 67 // func[GetAbnormalLevel]
func_call 68 // func[SetDBValue]
func_call 74 // func[Pledge_GetLeader]
func_call 76 // func[GetPledge]
func_call 77 // func[GiveItem1]
func_call 80 // func[DeleteItem1]
func_call 81 // func[OwnItemCount]
func_call 83 // func[GetLastAttacker]
func_call 84 // func[FHTML_SetFileName]
func_call 85 // func[FHTML_SetInt]
func_call 86 // func[FHTML_SetFloat]
func_call 87 // func[FHTML_SetStr]
func_call 88 // func[ShowFHTML]
func_call 89 // func[MakeFString]
func_call 100 // func[IsMyLord]
func_call 103 // func[Castle_GetSiegeTime]
func_call 104 // func[Residence_GetTaxRate]
func_call 105 // func[Residence_GetTaxRateCurrent]
func_call 106 // func[Residence_SetTaxRate]
func_call 111 // func[Residence_VaultTakeOutMoney]
func_call 114 // func[Castle_GateOpenClose]
func_call 115 // func[Castle_GetPledgeState]
func_call 116 // func[Castle_IsUnderSiege]
func_call 117 // func[Castle_GetHPRegen]
func_call 118 // func[Castle_GetMPRegen]
func_call 119 // func[Castle_BanishOthers]
func_call 120 // func[Castle_SetHPRegen]
func_call 121 // func[Castle_SetMPRegen]
func_call 122 // func[Castle_GetRawSiegeTime]
func_call 123 // func[Castle_GetRawSystemTime]
func_call 125 // func[Castle_GateOpenClose2]
func_call 126 // func[Castle_GetPledgeId]
func_call 127 // func[Castle_GetLifeControlLevel]
func_call 128 // func[Agit_SetMaster]
func_call 129 // func[Agit_GetTeleportLevel]
func_call 130 // func[Agit_SetTeleportLevel]
func_call 131 // func[AddChoice]
func_call 132 // func[ShowChoicePage]
func_call 133 // func[ShowSkillList]
func_call 134 // func[ShowGrowSkillMessage]
func_call 143 // func[IsInCategory]
func_call 144 // func[ClassChange]
func_call 145 // func[Castle_GetCropRate]
func_call 146 // func[Castle_GetCropPrice]
func_call 148 // func[Residence_GetTaxIncome]
func_call 152 // func[Castle_PostCropPurchase]
func_call 154 // func[Skill_GetConsumeHP]
func_call 155 // func[Skill_GetConsumeMP]
func_call 156 // func[Skill_GetEffectPoint]
func_call 157 // func[Skill_GetAttribute]
func_call 158 // func[Skill_GetAbnormalType]
func_call 160 // func[Skill_InReuseDelay]
func_call 165 // func[CreatePrivates]
func_call 166 // func[CreateOnePrivate]
func_call 168 // func[Maker_GetNpcCount]
func_call 169 // func[Maker_FindNpcByKey]
func_call 170 // func[CreateOnePrivateEx]
func_call 171 // func[IncrementParam]
func_call 173 // func[SoundEffect]
func_call 174 // func[EffectMusic]
func_call 175 // func[Despawn]
func_call 177 // func[InMyTerritory]
func_call 178 // func[InstantTeleportInMyTerritory]
func_call 180 // func[EarthQuakeByNPC]
func_call 181 // func[SpecialCamera]
func_call 184 // func[PledgeLevelUp]
func_call 188 // func[ShowTutorialHTML]
func_call 189 // func[ShowTutorialHTML2]
func_call 190 // func[ShowQuestionMark]
func_call 192 // func[CloseTutorialHTML]
func_call 193 // func[EnableTutorialEvent]
func_call 194 // func[ShowRadar]
func_call 195 // func[DeleteRadar]
func_call 196 // func[CreatePet]
func_call 200 // func[OpenSiegeInfo]
func_call 201 // func[SetDoorHpLevel]
func_call 202 // func[GetDoorHpLevel]
func_call 203 // func[SetControlTowerLevel]
func_call 204 // func[GetControlTowerLevel]

这些函数只能独立在的handler中被使用� ��而且各个函数有不同的变量格式。
举个例子:
我们从ai中提取出fun_call 43的运用方法:
shift_sp 1
push_event // talker
push_const 32
add
fetch_i
S0. "noquest.htm"
push_string S0
func_call 43 // func[ShowPage]
shift_sp -2
shift_sp -1
好了,开始分析
shift_sp 1 ---------事件进栈
push_event // talker ---压入事件开始
push_const 32 -----压入事件值,32代表的是对话者
add
fetch_i
S0. "noquest.htm" -----S0标志,相当于一个define
push_string S0 ------压出字节,那么这些字节怎么处理呢� �往下看,这个就是函数来处理了
func_call 43 // func[ShowPage] -----说明把S0所代表的用43这个函数处理
shift_sp -2 -----showpaga事件出栈
shift_sp -1 --函数出栈
从这里我们就看出了这个函数工作时� �需要的变量string,也就是htm页面。
再深入一些,这个事件在客户段我们� �行将是什么效果呢?
我们点一个NPC,他是否跟我们说话,� �是它控制的^_^,好了,第一个秘密浮� ��水面了。

下面我写一段小handler来说明简单的hand ler应该怎么写。
假设我们要写一个npc的行为就是当人� �他说话的时候他无意识的跟我们对话� ��
分析,这个事件其实就是一个对talk事� ��的处理,因为是无意识控制,那么我 们只要在handler中正确使用fun 43就好了。

handler 3 // TALKED ------声明处理的事件是当(玩家)跟"我"对 话的时候我该怎么做的事件处理
variable_begin -------开始
"talker"
"myself"
"_choiceN"
"_code"
"_from_choice"
variable_end -------------结束,从开始到结束这段是每个handler� ��定的,不同的handler有不同的这部分� �大家可以对应的提取出来,这样方便� ��后的编写

shift_sp 1 ---事件开始,数据进栈
push_event // talker ---压入事件,说话者
push_const 32 ------声明压入的事件是32号事件,代表的是 说话者
add
fetch_i
S0. "hello.htm"
push_string S0 ----给下面的函数压入string S0,该怎么处理呢?往下面看
func_call 43 // func[ShowPage] -------说明的是展现给玩家S0所代表的页面
shift_sp -2 --------事件结束 小问题:这里为什么是-2呢?我们往前看,前面出现了push_const 32和push_string S0两个变量的负值行为,这里函数要清 空,那么自然就是-2了
shift_sp -1 ------主事件结束 这里的-1对应的是开始的1。
handler_end -----------handler结束

这样就清楚地写完了一个小小的功能� �

大家服务器都有自己的特色吧?!那� �我们为何不用这段小小的程序来完成� ��个巨大的功能呢?我们可以自己写一 个介绍自己服务器的htm文件,然后再� �手出生的地方刷一个NPC,NPC的行为就� ��无意识展现htm文件。该怎么做我想看 了这三部分已经没有问题了吧。

好了,这部分就介绍到这里,内容虽� �少,但是需要大家提取的东西特别多� ��我多留一些时间,我再发SP4。

sp4预告:AI中多判断控制过程的实现。
Digital is offline  
Old 14.04.2006, 13:04   #2
wton
Архивный участник
 
Join Date: May 2005
Posts: 463
Default

traslation to english please o.O
wton is offline  
Old 14.04.2006, 17:31   #3
TheOrder
Архивный участник
 
Join Date: Sep 2005
Posts: 731
Default

If you can traslate it , would be of good help for all of us . Tnx Digi !!!
TheOrder is offline  
Old 14.04.2006, 18:36   #4
kgptzac
Архивный участник
 
Join Date: Jan 2006
Posts: 363
Default

ooOOoOOOOoOOO

wow that's really had to understasnd... gl in translating XD
kgptzac is offline  
Old 15.04.2006, 02:03   #5
Digital
Архивный участник
 
Join Date: Nov 2004
Posts: 1,405
Default

well.. i could translate it...
but it'll take sometime tho... (busy busy life)
Digital is offline  
Old 15.04.2006, 02:09   #6
Sire
Архивный участник
 
Join Date: Feb 2006
Posts: 87
Default

W000t. Thanks digi. I can't read a thing in there but I'm sure it's awesome. I've actually started a new called digism. And all your breakdowns and tutorials are our bible.
Sire is offline  
Old 15.04.2006, 11:46   #7
wton
Архивный участник
 
Join Date: May 2005
Posts: 463
Default

Quote:
well.. i could translate it...
but it'll take sometime tho... (busy busy life)
o thnaks digital, waiting for the translation xD...

thx,thx,thx
wton is offline  
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 19:24.