コード例 #1
0
ファイル: Player.Map.cs プロジェクト: jungrok5/CypherCore
        public InstanceBind BindToInstance(InstanceSave save, bool permanent, BindExtensionState extendState = BindExtensionState.Normal, bool load = false)
        {
            if (save != null)
            {
                InstanceBind bind = new InstanceBind();
                if (m_boundInstances[(int)save.GetDifficultyID()].ContainsKey(save.GetMapId()))
                {
                    bind = m_boundInstances[(int)save.GetDifficultyID()][save.GetMapId()];
                }

                if (extendState == BindExtensionState.Keep) // special flag, keep the player's current extend state when updating for new boss down
                {
                    if (save == bind.save)
                    {
                        extendState = bind.extendState;
                    }
                    else
                    {
                        extendState = BindExtensionState.Normal;
                    }
                }

                if (!load)
                {
                    PreparedStatement stmt;
                    if (bind.save != null)
                    {
                        // update the save when the group kills a boss
                        if (permanent != bind.perm || save != bind.save || extendState != bind.extendState)
                        {
                            stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHAR_INSTANCE);

                            stmt.AddValue(0, save.GetInstanceId());
                            stmt.AddValue(1, permanent);
                            stmt.AddValue(2, extendState);
                            stmt.AddValue(3, GetGUID().GetCounter());
                            stmt.AddValue(4, bind.save.GetInstanceId());

                            DB.Characters.Execute(stmt);
                        }
                    }
                    else
                    {
                        stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_CHAR_INSTANCE);
                        stmt.AddValue(0, GetGUID().GetCounter());
                        stmt.AddValue(1, save.GetInstanceId());
                        stmt.AddValue(2, permanent);
                        stmt.AddValue(3, extendState);
                        DB.Characters.Execute(stmt);
                    }
                }

                if (bind.save != save)
                {
                    if (bind.save != null)
                    {
                        bind.save.RemovePlayer(this);
                    }
                    save.AddPlayer(this);
                }

                if (permanent)
                {
                    save.SetCanReset(false);
                }

                bind.save        = save;
                bind.perm        = permanent;
                bind.extendState = extendState;
                if (!load)
                {
                    Log.outDebug(LogFilter.Maps, "Player.BindToInstance: Player '{0}' ({1}) is now bound to map (ID: {2}, Instance {3}, Difficulty {4})", GetName(), GetGUID().ToString(), save.GetMapId(), save.GetInstanceId(), save.GetDifficultyID());
                }

                Global.ScriptMgr.OnPlayerBindToInstance(this, save.GetDifficultyID(), save.GetMapId(), permanent, extendState);

                m_boundInstances[(int)save.GetDifficultyID()][save.GetMapId()] = bind;
                return(bind);
            }

            return(null);
        }