Ejemplo n.º 1
0
void Script::CallScriptByGUID(const CGUID& shapeGuid, const char* scriptFilename)
{
	CMoveShape* shape = GetGame()->FindShape(TYPE_PLAYER, shapeGuid);
	if(shape==NULL)
	{
		CServerRegion* region = dynamic_cast<CServerRegion*>(m_RunEnv.region);
		if(region != NULL)
			shape = dynamic_cast<CMoveShape*>(region->FindChildObject(TYPE_MONSTER, shapeGuid));
	}

	if(shape != NULL) // 本地调用脚本
	{
		RunEnv env;
		env.region = dynamic_cast<CRegion*>(shape->GetFather());
		env.srcShape = shape;
		GetInst(ScriptSys).RunScript(env, scriptFilename);
	}
	else // 跨服调用脚本
	{
		CMessage msg(MSG_S2W_QUEST_PlayerRunScript);
		msg.Add(shapeGuid); // call guid
		msg.Add(scriptFilename);	 // called script name
		msg.SendToSocket(GetGame()->GetWSSocket());
	}
}
Ejemplo n.º 2
0
    int SkillTracer::Run(BaseAI *ai)
    {
        if(timeGetTime() >= m_EndTime)
        {
            return TIMEOUT;
        }
        CMoveShape *self = ai->GetOwner();
        CServerRegion *rgn = dynamic_cast<CServerRegion*>(self->GetFather());
        CMoveShape *target = AIUtils::FindShape(rgn, m_TargetID);
        if(target == NULL)
        {
            return FAILED;
        }
#ifdef MONSTER_DIS_FLOAT
        float dis = self->RealDistanceF(target);
#else
        long dis = self->Distance(target);
#endif
        long dx = target->GetTileX();
        long dy = target->GetTileY();
        if(dis > m_SkillMaxDis)
        {
            ai->Move(dx, dy);
        }
        else if(dis < m_SkillMinDis)
        {
            long dir = GetLineDir(dx, dy, self->GetTileX(), self->GetTileY());
            ai->Move(dir);
        }
        else
        {
            return Okay;
        }
        return RUNNING;
    }
Ejemplo n.º 3
0
    bool PetAI::SearchEnemy()
    {
        CPet *owner = (CPet*) m_Owner;
        CMoveShape *host = owner->GetHost();
        if(NULL == host)
        {
			LogError(AI_MODULE, "m_Owner->GetHost() error.");
            return false;
        }
        CMoveShape *target = GetTarget();

        // 当前有追踪目标
        if(target != NULL)
        {
            long dis = owner->Distance(target);
            long tracDis = owner->GetTrackRange();
            if(!target->IsDied() &&
                tracDis > dis &&
                !target->IsGod())
            {
                return true;
            }
        }

        // 寻找所在场景
        CServerRegion *region = dynamic_cast<CServerRegion*>(host->GetFather());
        if(NULL == region)
        {
            return false;
        }

        vector<CShape*> vOut;
        region->FindAroundObject(owner, TYPE_PLAYER, vOut);
        region->FindAroundObject(owner, TYPE_MONSTER, vOut);
        region->FindAroundObject(owner, TYPE_PET, vOut);

        bool ret = false;
        map<long, CMoveShape*> AroundObjs;
        long distance = 0;
        for(size_t i=0; i < vOut.size(); ++i)
        {
            target = (CMoveShape*)vOut[i];
            if(target != NULL &&
                target->IsDied() &&
                !target->IsGod() &&
                target->IsAttackAble(owner))
            {
                distance = m_Owner->Distance(target->GetTileX(), target->GetTileY());
                AroundObjs[distance] = target;
                ret = true;
            }
        }

        if(ret)		// 满足条件设置对象
        {
            map<long, CMoveShape*>::iterator itr = AroundObjs.begin();
            target = itr->second;
            SetTarget(target->GetExID(), target->GetType());
            //if(PET_TYPE_TRAP == owner->GetPetType())
            //{
            //    owner->SetActTime(0, 0);		// 避免寻敌后无法攻击
            //    owner->OnTrapSpring();
            //}
        }

        return true;
    }