Ejemplo n.º 1
0
        // Применить изменение
        private void ApplyChange(OutgoingMessage changeMessage)
        {
            if (changeMessage is AddObjects addObjMsg)
            {
                // Добавление новых сущностей
                var objectsToAdd = addObjMsg.GetOrigObjects();
                Room.Entities.AddRange(objectsToAdd);
            }
            else if (changeMessage is RemoveObjects delObjMsg)
            {
                // Удаление сущностей
                var objectsToRemove = Room.GetEntitiesById(delObjMsg.ObjectIds);
                foreach (var obj in objectsToRemove)
                {
                    Room.Entities.Remove(obj);
                }
            }
            else if (changeMessage is SessionPropertyChange propMsg)
            {
                // Изменение свойства
                PropertyBag[propMsg.Name] = propMsg.Value;
            }
            else if (changeMessage is MoveObject moveMsg)
            {
                // Перемещение объекта
                var gameObj = Room.GetEntitiesById(moveMsg.ObjectId).First();

                if (moveMsg.TargetPosition != null)
                {
                    gameObj.Position = moveMsg.TargetPosition;
                }
                if (moveMsg.TargetRotation != null)
                {
                    gameObj.Rotation = moveMsg.TargetRotation;
                }
                if (moveMsg.TargetLayoutId != null)
                {
                    gameObj.LayoutId = moveMsg.TargetLayoutId;
                }
            }
            else if (changeMessage is PlayerTurn turnMsg)
            {
                // Смена очередности хода
                ActivePlayer = GetPlayerById(turnMsg.PlayerId);
            }
            else if (changeMessage is AddDefinitions newDefsMsg)
            {
                // Добавление новых определений
                string tmpl = newDefsMsg.TemplateDefName;
                ResourceManager.AddDefinitionClones(tmpl, newDefsMsg.NewDefNames);
            }
        }