Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

[Core/SAI] SMART_ACTION_SET_HOME_POS #11593

Open
xinef1 opened this Issue Feb 11, 2014 · 6 comments

Comments

Projects
None yet
4 participants

xinef1 commented Feb 11, 2014

Rev: b722730

What's wrong:
Current implementation of SmartAction SMART_ACTION_SET_HOME_POS is very poor. In example it won't work at all with target type SMART_TARGET_POSITION because GetTargets function returns null pointer to ObjectList if this target is used.

Anyway the way it works is really stupid and allows to set HomePosition of creature only to its current position (plus GameObject targets are being checked under IsCreature condition which is dumb).

Description of changes:
At first movers ObjectList is being created exacly as casters in SMART_ACTION_CROSS_CAST. This list containts all objects that will have their HomePosition changed. If target type is equal to SMART_TARGET_POSITION all objects from the list will have their HomePosition set to x, y, z, o of target coordinates. Otherwise if any other target type is used, all movers will have their HomePosition set to coordinates of first object from targets ObjectList.

Proposed code:
SmartScript.cpp

        case SMART_ACTION_SET_HOME_POS:
        {
            ObjectList* movers = GetTargets(CreateEvent(SMART_EVENT_UPDATE_IC, 0, 0, 0, 0, 0, SMART_ACTION_NONE, 0, 0, 0, 0, 0, 0, (SMARTAI_TARGETS)e.action.sethome.targetType, e.action.sethome.targetParam1, e.action.sethome.targetParam2, e.action.sethome.targetParam3, 0), unit);
            if (!movers)
                break;

            if (e.GetTargetType() == SMART_TARGET_POSITION)
            {
                for (ObjectList::const_iterator itr = movers->begin(); itr != movers->end(); ++itr)
                    if (IsCreature(*itr))
                        (*itr)->ToCreature()->SetHomePosition(e.target.x, e.target.y, e.target.z, e.target.o);
            }
            else if (ObjectList* targets = GetTargets(e, unit))
            {
                if (WorldObject* target = targets->front())
                    for (ObjectList::const_iterator itr = movers->begin(); itr != movers->end(); ++itr)
                        if (IsCreature(*itr))
                            (*itr)->ToCreature()->SetHomePosition(target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), target->GetOrientation());

                delete targets;
            }

            delete movers;
            break;
        }

Of course you have to take care of header files and database conversion which is not included in this ticket.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

xinef1 commented Feb 11, 2014

Similar extension can be used for action SMART_ACTION_MOVE_TO_POS.
Just replace SetHomePosition with GetMotionMaster()->MovePoint(x, y, z) and the above code can be freely used (with some naming changes and transport code included).

Contributor

jasperrietrae commented Feb 13, 2014

Nice find. Next time please make a pull request like all others please. 😄

(plus GameObject targets are being checked under IsCreature condition which is dumb).

What do you mean? SmartScript::IsCreature doesn't return true for gameobjects, only for creatures.

Owner

Aokromes commented May 26, 2016

If the fix here is valid, plz open a PR.

Owner

Aokromes commented Jul 5, 2016

@xinef1 this is correct? or code needs to be updated?

Aokromes/TrinityCore@414e56c

Owner

Aokromes commented Jul 6, 2016

I need sql for conversion of data.

Contributor

Rushor commented Mar 8, 2017

from sunwellcore:

case SMART_ACTION_SET_HOME_POS:
        {
            ObjectList* targets = GetTargets(e, unit);
            if (targets)
            {
                float x, y, z, o;
                for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
                    if (IsCreature(*itr))
                    {
                        if (e.action.setHomePos.spawnPos)
                        {
                            (*itr)->ToCreature()->GetRespawnPosition(x, y, z, &o);
                            (*itr)->ToCreature()->SetHomePosition(x, y, z, o);
                        }
                        else
                            (*itr)->ToCreature()->SetHomePosition((*itr)->GetPositionX(), (*itr)->GetPositionY(), (*itr)->GetPositionZ(), (*itr)->GetOrientation());

                    }
                delete targets;
            }
            else if (me && e.GetTargetType() == SMART_TARGET_POSITION)
            {
                if (e.action.setHomePos.spawnPos)
                {
                    float x, y, z, o;
                    me->GetRespawnPosition(x, y, z, &o);
                    me->SetHomePosition(x, y, z, o);
                }
                else
                    me->SetHomePosition(e.target.x, e.target.y, e.target.z, e.target.o);
            }
            break;
        }

of course uint32 setHomePos definitions needs to be added in the header file of sai too

@Rushor Rushor referenced this issue in dalaranwow/dalaran-wow Mar 8, 2017

Closed

[NPC][WotlK] Farunn, missing path #4520

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment