Пример #1
0
        private static void Room_AddObject(On.Room.orig_AddObject orig, Room self, UpdatableAndDeletable obj)
        {
            if (self.game == null)
            {
                return;
            }

            if (obj is WaterGate)
            {
                // Add electric gate
                if (self.abstractRoom.gate)
                {
                    CustomWorldMod.Log("Water gate created, checking if it should be electric...");
                    foreach (KeyValuePair <string, string> regions in CustomWorldMod.activatedPacks)
                    {
                        if (CustomWorldMod.installedPacks[regions.Key].electricGates != null)
                        {
                            if (CustomWorldMod.installedPacks[regions.Key].electricGates.ContainsKey(self.abstractRoom.name))
                            {
                                (obj as WaterGate).Destroy();
                                CustomWorldMod.Log($"Added electric gate [{self.abstractRoom.name}] from [{regions.Value}]");
                                self.regionGate = new ElectricGate(self);
                                (self.regionGate as ElectricGate).meterHeight = CustomWorldMod.installedPacks[regions.Key].electricGates[self.abstractRoom.name];
                                obj = self.regionGate;
                                break;
                            }
                        }
                    }
                }
            }

            orig(self, obj);
        }
        private static void Room_AddObject(On.Room.orig_AddObject orig, Room self, UpdatableAndDeletable obj)
        {
            orig(self, obj);

            if (obj is PhysicalObject pObj)  // Inform clients of added object


            {
                PhysicalObjects[ServerMonkScript.GetNewID()] = pObj;
            }
        }
Пример #3
0
 public void RemoveObject(UpdatableAndDeletable obj)
 {
     //移除房间引用
     if (obj.room == this)
     {
         obj.RemoveFromRoom();
     }
     //更新UpdateLst
     if (this.updateList.IndexOf(obj) > this.updateIndex)
     {
         this.CleanOutObjectNotInThisRoom(obj);
     }
 }
Пример #4
0
    public void Update()
    {
        if (this.game == null)
        {
            return;
        }

        //遍历并更新整个UpdatableAndDeletable 列表
        this.updateIndex = this.updateList.Count - 1;
        while (this.updateIndex >= 0)
        {
            UpdatableAndDeletable updateObj = this.updateList[this.updateIndex];
            if (updateObj.slatedForDeletetion || updateObj.room != this)
            {
                //准备删除 or 不属于本房间
                this.CleanOutObjectNotInThisRoom(updateObj);
            }
            else
            {
                //调用抽象接口Update
                updateObj.Update(this.game.evenUpdate);

                if (updateObj.slatedForDeletetion || updateObj.room != this)
                {
                    //有可能Update之后信息发生变化,因此需要再次检测
                    this.CleanOutObjectNotInThisRoom(updateObj);
                }
                else if (updateObj is PhysicalObject)
                {
                    //如果是物理对象
                    if ((updateObj as PhysicalObject).graphicsModule != null)
                    {
                        //表现层更新
                        (updateObj as PhysicalObject).graphicsModule.Update();
                        //变现层更新后  更新
                        (updateObj as PhysicalObject).GraphicsModuleUpdated(true, this.game.evenUpdate);
                    }
                    else
                    {
                        (updateObj as PhysicalObject).GraphicsModuleUpdated(false, this.game.evenUpdate);
                    }
                }
            }
            this.updateIndex--;
        }
        this.updateIndex = int.MaxValue;

        //物理碰撞检测
        this.CheckPhycicalCollision();
    }
Пример #5
0
    //TODO 优化
    public void AddObject(UpdatableAndDeletable obj)
    {
        if (this.game == null)
        {
            return;
        }

        Debug.Log("添加列表管理");
        this.updateList.Add(obj);
        obj.room = this;

        IDrawable drawable = null;

        if (obj is IDrawable)
        {
            drawable = (obj as IDrawable);
        }

        //添加物理对象管理
        PhysicalObject phyObj = null;

        if (obj is PhysicalObject)
        {
            phyObj = obj as PhysicalObject;
            this.physicalObjects[phyObj.collisionLayer].Add(phyObj);
            if (phyObj.graphicsModule != null)
            {
                drawable = phyObj.graphicsModule;
            }
            else if (true)
            //else if (this.BeingViewed)
            {
                phyObj.InitiateGraphicsModule();
                if (phyObj.graphicsModule != null)
                {
                    drawable = phyObj.graphicsModule;
                }
            }
        }
        //添加drawable
        if (drawable != null)
        {
            this.drawableObjects.Add(drawable);
            if (this.game.Camera.room == this)
            {
                this.game.Camera.NewObjectInRoom(drawable);
            }
        }
    }
Пример #6
0
    private void CleanOutObjectNotInThisRoom(UpdatableAndDeletable obj)
    {
        //移除UpdateLst
        this.updateList.Remove(obj);
        //移除Drawable引用
        if (obj is IDrawable)
        {
            this.drawableObjects.Remove(obj as IDrawable);
        }

        //移除物理对象
        if (obj is PhysicalObject)
        {
            this.physicalObjects[(obj as PhysicalObject).collisionLayer].Remove(obj as PhysicalObject);
            if ((obj as PhysicalObject).graphicsModule != null)
            {
                this.drawableObjects.Remove((obj as PhysicalObject).graphicsModule);
            }
        }
        this.RemoveObject(obj);
    }
 private static void Room_RemoveObject(On.Room.orig_RemoveObject orig, Room self, UpdatableAndDeletable obj)
 {
     orig(self, obj);
 }
Пример #8
0
 private static void LightSource_ctor(On.LightSource.orig_ctor orig, LightSource self, Vector2 initPos, bool environmentalLight, Color color, UpdatableAndDeletable tiedToObject)
 {
     if (tiedToObject is Player)
     {
         color = KarmaAppetite.GranOrange;
     }
     orig.Invoke(self, initPos, environmentalLight, color, tiedToObject);
 }