[閒聊] RO的獵人老鷹->寵物系統

作者: taily (準農夫)   2019-07-30 13:25:00
實例影片: https://youtu.be/9L5XtcGnGiU
以下code是es2內建的, 只是原始碼我一直沒看到他的應用~
後來就寫個寵物系統給他:(有興趣的稍微看一下,應該就懂了)
mapping *read_table(string file)
{
string *line, *field, *format;
mapping *data;
int i, rn, fn;
line = explode(read_file(file), "\n");
data = ({});
for(i=0; i<sizeof(line); i++) {
if( line[i]=="" || line[i][0]=='#' ) continue;
if( !pointerp(field) ) {
field = explode( line[i], ":" );
continue;
}
if( !pointerp(format) ) {
format = explode( line[i], ":" );
continue;
}
break;
}
for( rn = 0, fn = 0; i<sizeof(line); i++) {
if( line[i]=="" || line[i][0]=='#' ) continue;
if( !fn ) data += ({ allocate_mapping(sizeof(field)) });
sscanf( line[i], format[fn], data[rn][field[fn]] );
fn = (++fn) % sizeof(field);
if( !fn ) ++rn;
}
return data;
}
之後只要在目錄上多寫個檔案link:
//data/pet/招式表
#招式
level:message:damage
%d:%s:%d
5
閃電衝擊
100
10
[勁]閃電衝擊
200
15
[夠勁]閃電衝擊
250
那之後就會有等級,學會招式跟傷害
接下來在pet物件上寫下:
mapping save_add = ([]);
void update_level()
{
object ob,me;
string message;
int i,count,level,damage;
mapping *data = read_table("/data/pet/招式表");
ob = this_object();
me = find_player( dbase["master_id"] );
for( i=0; i<sizeof(data) ; i++) {
if( dbase["level"] == data[i]["level"] ) {
level = data[i]["level"];
message = data[i]["message"];
damage = data[i]["damage"];
message_vision(HIR"\n$N領悟了一招「"+message+"」!\n"NOR,ob);
if( wizardp(me) )
message_vision(HIR"傷害值:"+damage+"等級:"+level+"。\n"NOR,me);
if( !count = sizeof(save_add) ) count = 0;
save_add[count] = data[i];
save();
break;
}
}
}
接下來, 看你是需要餵食跟還是跟玩家經驗直一起成長up_level
然後領悟招式save()下來就可以了...
攻擊招式perform()我是寫在寵物heart_beat()身上:
int perform(object master)
{
int i,num,level,damage;
string *killer= master->query_killer();
object *enemy= master->query_enemy();
num = random(sizeof(save_add));
if( !level = save_add[num]["level"] ) return 0;
//通通打!!
for( i=0; i<sizeof(enemy); i++ ){
if( member_array( enemy[i]->query("id"), killer )!=-1 ){
damage = random(save_add[num]["damage"]/2) + save_add[num]["damage"]/2;
message_vision(HIR"轟~轟~轟~\n$N使出一招"NOR+level+NOR"級奧義"
+HIM"「"NOR+save_add[num]["message"]+HIM"」"
+HIC"讓$n造成("HIR+damage+HIC")的傷害!\n"NOR,this_object(),enemy[i]);
enemy[i]->receive_damage("kee",damage);
}
}
return 1;
}

Links booklink

Contact Us: admin [ a t ] ucptt.com