예제 #1
0
        static void CheckUpdateAll(StoredCustomModel storedCustomModel)
        {
            // re-define the model and do ChangeModel for each entity currently using this model

            // remove this model from everyone's sent list
            foreach (Player p in PlayerInfo.Online.Items)
            {
                lock (SentCustomModels) {
                    var sentModels = SentCustomModels[p.name];
                    foreach (var modelName in sentModels.ToArray())
                    {
                        if (storedCustomModel.GetModelFileName().CaselessEq(new StoredCustomModel(modelName).GetModelFileName()))
                        {
                            Debug("CheckUpdateAll remove {0} from {1}", modelName, p.name);
                            CheckRemoveModel(p, modelName);
                        }
                    }
                }
            }

            // add this model back to players who see entities using it
            foreach (Player p in PlayerInfo.Online.Items)
            {
                CheckAddRemove(p, p.level);
            }

            void checkEntity(Entity e)
            {
                if (new StoredCustomModel(e.Model).Exists())
                {
                    e.UpdateModel(e.Model);
                }
            }

            // do ChangeModel on every entity with this model
            // so that we update the model on the client
            var loadedLevels = new Dictionary <string, Level>(StringComparer.OrdinalIgnoreCase);

            foreach (Player p in PlayerInfo.Online.Items)
            {
                checkEntity(p);

                if (p.Extras.TryGet("TempBot_BotList", out object obj))
                {
                    if (obj != null)
                    {
                        List <PlayerBot> botList = (List <PlayerBot>)obj;
                        foreach (var bot in botList)
                        {
                            checkEntity(bot);
                        }
                    }
                }

                if (!loadedLevels.ContainsKey(p.level.name))
                {
                    loadedLevels.Add(p.level.name, p.level);
                }
            }
            foreach (var entry in loadedLevels)
            {
                var level = entry.Value;
                foreach (PlayerBot e in level.Bots.Items)
                {
                    checkEntity(e);
                }
            }
        }