Пример #1
0
        bool Create(ulong lowGuid, uint conversationEntry, Map map, Unit creator, Position pos, List <ObjectGuid> participants, SpellInfo spellInfo = null)
        {
            ConversationTemplate conversationTemplate = Global.ConversationDataStorage.GetConversationTemplate(conversationEntry);

            //ASSERT(conversationTemplate);

            _creatorGuid  = creator.GetGUID();
            _participants = participants;

            SetMap(map);
            Relocate(pos);

            _Create(ObjectGuid.Create(HighGuid.Conversation, GetMapId(), conversationEntry, lowGuid));
            PhasingHandler.InheritPhaseShift(this, creator);

            SetEntry(conversationEntry);
            SetObjectScale(1.0f);

            SetUInt32Value(ConversationFields.LastLineEndTime, conversationTemplate.LastLineEndTime);
            _duration     = conversationTemplate.LastLineEndTime;
            _textureKitId = conversationTemplate.TextureKitId;

            for (ushort actorIndex = 0; actorIndex < conversationTemplate.Actors.Count; ++actorIndex)
            {
                ConversationActorTemplate actor = conversationTemplate.Actors[actorIndex];
                if (actor != null)
                {
                    ConversationDynamicFieldActor actorField = new ConversationDynamicFieldActor();
                    actorField.ActorTemplate.CreatureId      = actor.CreatureId;
                    actorField.ActorTemplate.CreatureModelId = actor.CreatureModelId;
                    actorField.Type = ConversationDynamicFieldActor.ActorType.CreatureActor;
                    SetDynamicStructuredValue(ConversationDynamicFields.Actors, actorIndex, actorField);
                }
            }

            for (ushort actorIndex = 0; actorIndex < conversationTemplate.ActorGuids.Count; ++actorIndex)
            {
                ulong actorGuid = conversationTemplate.ActorGuids[actorIndex];
                if (actorGuid == 0)
                {
                    continue;
                }

                foreach (var creature in map.GetCreatureBySpawnIdStore().LookupByKey(actorGuid))
                {
                    // we just need the last one, overriding is legit
                    AddActor(creature.GetGUID(), actorIndex);
                }
            }

            Global.ScriptMgr.OnConversationCreate(this, creator);

            List <ushort> actorIndices = new List <ushort>();

            foreach (ConversationLineTemplate line in conversationTemplate.Lines)
            {
                actorIndices.Add(line.ActorIdx);
                AddDynamicStructuredValue(ConversationDynamicFields.Lines, line);
            }

            // All actors need to be set
            foreach (ushort actorIndex in actorIndices)
            {
                ConversationDynamicFieldActor actor = GetDynamicStructuredValue <ConversationDynamicFieldActor>(ConversationDynamicFields.Actors, actorIndex);
                if (actor == null || actor.IsEmpty())
                {
                    Log.outError(LogFilter.Conversation, $"Failed to create conversation (Id: {conversationEntry}) due to missing actor (Idx: {actorIndex}).");
                    return(false);
                }
            }

            if (!GetMap().AddToMap(this))
            {
                return(false);
            }

            return(true);
        }