Example #1
0
void merchant_driver(int cn,int ret,int lastact)
{
	struct merchant_driver_data *dat;
        int co,in,n;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_MERCHANTDRIVER,sizeof(struct merchant_driver_data));
	if (!dat) return;	// oops...

        if (ch[cn].arg) {
		dat->open=6; dat->close=23;
		merchant_driver_parse(cn,dat);
		ch[cn].arg=NULL;
	}
	if (!ch[cn].store) {
		if (dat->pricemulti) create_store(cn,dat->ignore,dat->pricemulti);
		else create_store(cn,dat->ignore,400);
		if (dat->special) {
			for (n=0; n<5; n++) add_special_store(cn);
		}
	}
	
	// loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

			// dont talk to the same person twice
			if (mem_check_driver(cn,co,7)) { remove_message(cn,msg); continue; }

			quiet_say(cn,"Hello %s! If you'd like to trade, say: '°c4%s, trade°c0!",ch[co].name,ch[cn].name);
			mem_add_driver(cn,co,7);
		}

                // talk back
		if (msg->type==NT_TEXT) {
			analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,msg->dat3);

			if ((msg->dat1==1 || msg->dat1==2) && (co=msg->dat3)!=cn) {	// talk, and not our talk
				if (strcasestr((char*)msg->dat2,ch[cn].name) &&
				    strcasestr((char*)msg->dat2,"trade")) {
					/*if (abuser(ch[co].ID)) {
						switch(RANDOM(3)) {
                                                        case 0:		murmur(cn,"I hate cheaters."); break;
							case 1:		emote(cn,"clenches his fists and stares at %s.",ch[co].name); break;
							case 2:		murmur(cn,"I wish the cheaters would leave me alone."); break;
						}
					}*/
					ch[co].merchant=cn;
				}
			}			
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it
				// let it vanish
				destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}

                remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	if (dat->dayx) {	// we have day / night positions
		if (!opening_time(dat->open,dat->close)) {	// we're closed
                        if (dat->doorx && !is_closed(dat->doorx,dat->doory)) {	// door is still open
				if (!is_room_empty(dat->storefx,dat->storefy,dat->storetx,dat->storety)) {	// store is not empty
					quiet_say(cn,"We're closing, please leave now!");
					do_idle(cn,TICKS);
					return;
				} else {
					if (use_item_at(cn,dat->doorx,dat->doory,0)) return;
					do_idle(cn,TICKS);
					return;
				}
			}
			if (secure_move_driver(cn,dat->nightx,dat->nighty,dat->nightdir,ret,lastact)) return;
		} else {	// we're open
                        if (dat->doorx && is_closed(dat->doorx,dat->doory)) {	// door is still closed
                                if (use_item_at(cn,dat->doorx,dat->doory,0)) return;
				do_idle(cn,TICKS);
				return;			
			}

			if (secure_move_driver(cn,dat->dayx,dat->dayy,dat->daydir,ret,lastact)) return;			
		}
	} else {		// just one position
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,dat->dir,ret,lastact)) return;		
	}

        if (ticker>dat->last_talk+TICKS*60 && !RANDOM(25)) {
		switch(RANDOM(11)) {
			case 0:		murmur(cn,"My back itches."); break;
			case 1:		whisper(cn,"There's something stuck between your teeth."); break;
			case 2:		murmur(cn,"Oh yeah, those were the days."); break;
			case 3:		murmur(cn,"Now where did I put it?"); break;
			case 4:		murmur(cn,"Oh my, life is hard but unfair."); break;
			case 5:		murmur(cn,"Beware of the fire snails!"); break;	
			case 6:		murmur(cn,"Ishtar! Oh, what has become of us!"); break;
			case 7:		murmur(cn,"The demons will get you."); break;
			case 8:		emote(cn,"scratches %s back",hisname(cn)); break;
			case 9:		if (map[ch[cn].x+ch[cn].y*MAXMAP].flags&MF_INDOORS) emote(cn,"stares at the ceiling");
					else emote(cn,"stares at the sky");
					break;
			case 10:	emote(cn,"twiddles %s thumbs",hisname(cn)); break;

			default:	break;
		}
		
		dat->last_talk=ticker;
	}
	if (dat->special && ticker>dat->lastadd+TICKS*60*60*12) {
		add_special_store(cn);
		dat->lastadd=ticker;
	}

	if (ticker>dat->memcleartimer) {
		mem_erase_driver(cn,7);
		dat->memcleartimer=ticker+TICKS*60*60*12;
	}

        do_idle(cn,TICKS*2);
}
        void UpdateAI(const uint32 diff)
        {
            //Inhibitmagic_Timer
            if (Inhibitmagic_Timer <= diff)
            {
                float dist;
                Map* map = me->GetMap();
                Map::PlayerList const &PlayerList = map->GetPlayers();
                for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i)
                    if (Player* i_pl = i->getSource())
                        if (i_pl->isAlive() && (dist = i_pl->IsWithinDist(me, 45)))
                        {
                            i_pl->RemoveAurasDueToSpell(SPELL_INHIBITMAGIC);
                            me->AddAura(SPELL_INHIBITMAGIC, i_pl);
                            if (dist < 35)
                                me->AddAura(SPELL_INHIBITMAGIC, i_pl);
                            if (dist < 25)
                                me->AddAura(SPELL_INHIBITMAGIC, i_pl);
                            if (dist < 15)
                                me->AddAura(SPELL_INHIBITMAGIC, i_pl);
                        }
                Inhibitmagic_Timer = 3000+(rand()%1000);
            } else Inhibitmagic_Timer -= diff;

            //Return since we have no target
            if (!UpdateVictim())
                return;

            //Attractmagic_Timer
            if (Attractmagic_Timer <= diff)
            {
                DoCast(me, SPELL_ATTRACTMAGIC);
                Attractmagic_Timer = 30000;
                Carnivorousbite_Timer = 1500;
            } else Attractmagic_Timer -= diff;

            //Carnivorousbite_Timer
            if (Carnivorousbite_Timer <= diff)
            {
                DoCast(me, SPELL_CARNIVOROUSBITE);
                Carnivorousbite_Timer = 10000;
            } else Carnivorousbite_Timer -= diff;

            //FocusFire_Timer
            if (FocusFire_Timer <= diff)
            {
                // Summon Focus Fire & Emote
                Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 1);
                if (target && target->GetTypeId() == TYPEID_PLAYER && target->isAlive())
                {
                    FocusedTargetGUID = target->GetGUID();
                    me->SummonCreature(ENTRY_FOCUS_FIRE, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 5500);

                    // TODO: Find better way to handle emote
                    // Emote
                    std::string emote(EMOTE_FOCUSES_ON);
                    emote.append(target->GetName());
                    emote.push_back('!');
                    me->MonsterTextEmote(emote.c_str(), 0, true);
                }
                FocusFire_Timer = 15000+(rand()%5000);
            } else FocusFire_Timer -= diff;

            DoMeleeAttackIfReady();
        }
Example #3
0
void warpfighter(int cn,int ret,int lastact)
{
    struct warpfighter_data *dat;
    struct msg *msg,*next;
    int co,in,fre;

    dat=set_data(cn,DRD_WARPFIGHTER,sizeof(struct warpfighter_data));
    if (!dat) return;	// oops...

    // loop through our messages
    for (msg=ch[cn].msg; msg; msg=next) {
        next=msg->next;

        switch(msg->type) {
        case NT_CREATE:
            fight_driver_set_dist(cn,40,0,40);
            dat->creation_time=ticker;
            break;

        case NT_TEXT:
            co=msg->dat3;
            tabunga(cn,co,(char*)msg->dat2);
            break;
        }


        standard_message_driver(cn,msg,1,0);
        remove_message(cn,msg);
    }

    // do something. whenever possible, call do_idle with as high a tick count
    // as reasonable when doing nothing.

    co=dat->co;
    if (!ch[co].flags || ch[co].serial!=dat->cser || ch[co].x<dat->xs || ch[co].y<dat->ys || ch[co].x>dat->xe || ch[co].y>dat->ye) {
        remove_char(cn);
        destroy_char(cn);
        //xlog("self-destruct %d %d %d %d %d %d (%d)",!ch[co].flags,ch[co].serial!=dat->cser,ch[co].x<dat->xs,ch[co].y<dat->ys,ch[co].x>dat->xe,ch[co].y>dat->ye,dat->co);
        return;
    }

    if (dat->pot_done<1 && ticker>dat->creation_time+TICKS*2) {
        dat->pot_done++;
        if (ch[cn].level>60 && !RANDOM(6)) {
            if (RANDOM(2)) {
                emote(cn,"drinks a potion of freeze");
                ch[cn].value[1][V_FREEZE]=ch[cn].value[1][V_ATTACK]+ch[cn].value[1][V_ATTACK]/4;
                ch[cn].value[1][V_MANA]=10;
                update_char(cn);
                ch[cn].mana=POWERSCALE*10;
            } else {
                if ((fre=may_add_spell(cn,IDR_FREEZE)) && (in=create_item("freeze_spell"))) {
                    emote(cn,"drinks a spoiled potion of freeze");
                    it[in].mod_value[0]=-ch[cn].value[0][V_SPEED]-100;
                    it[in].driver=IDR_FREEZE;
                    it[in].carried=cn;
                    ch[cn].item[fre]=in;
                    *(signed long*)(it[in].drdata)=ticker+TICKS*60;
                    *(signed long*)(it[in].drdata+4)=ticker;
                    create_spell_timer(cn,in,fre);
                    update_char(cn);
                }
            }
        }
    }

    if (ch[cn].lifeshield<POWERSCALE*5 && ch[cn].endurance<ch[cn].value[0][V_WARCRY]*POWERSCALE/3 && dat->pot_done<3) {
        dat->pot_done++;
        if (ch[cn].level>50 && !RANDOM(4)) {
            emote(cn,"drinks an endurance potion");
            ch[cn].endurance=min(ch[cn].value[0][V_ENDURANCE]*POWERSCALE,ch[cn].endurance+32*POWERSCALE);
        }
    }

    if (ch[cn].hp<ch[cn].value[0][V_ENDURANCE]*POWERSCALE/2 && dat->pot_done<5) {
        dat->pot_done++;
        if (ch[cn].level>40 && !RANDOM(4)) {
            emote(cn,"drinks a healing potion");
            ch[cn].hp=min(ch[cn].value[0][V_HP]*POWERSCALE,ch[cn].hp+32*POWERSCALE);
        }
    }

    fight_driver_update(cn);
    if (fight_driver_attack_visible(cn,0)) return;
    if (fight_driver_follow_invisible(cn)) return;

    if (regenerate_driver(cn)) return;
    if (spell_self_driver(cn)) return;

    if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_DOWN,ret,lastact)) return;

    do_idle(cn,TICKS);
}