예제 #1
0
 static void NewObject()
 {
     foreach (UIButton b in objectData.drops)
     {
         if (b is UITypeBox tb)
         {
             tb.DisableTyping();
             tb.UpdatePublicVar();
         }
     }
     foreach (object o in ntParams)
     {
         if (o == null)
         {
             return;
         }
     }
     try {
         WorldObjectBase obj = (WorldObjectBase)Activator.CreateInstance(nt, ntParams);
         WorldData.AddToRegion(WorldData.WorldToRegion(obj.worldX), WorldData.WorldToRegion(obj.worldY), obj);
         applyBut.Visible = false;
         SetCurrentObject(obj);
     } catch (Exception e) {
         System.Diagnostics.Debug.WriteLine(e.Message);
     }
 }
예제 #2
0
 public static void SetCurrentObject(WorldObjectBase obj)
 {
     currentObject     = obj;
     checkWorldObjects = false;
     Screen.OpenWindow("worldBuilder");
     tabs.SetTab(0);
     UpdateObjectInfo();
 }
예제 #3
0
        /// <summary>
        /// Adds a given WorldObject to the region given by the region coordinates
        /// </summary>
        /// <param name="rx"></param>
        /// <param name="ry"></param>
        /// <param name="b"></param>
        public static void AddToRegion(int rx, int ry, WorldObjectBase b)
        {
            RegionTag reg = new RegionTag(rx, ry);

            if (currentRegions.ContainsKey(reg))
            {
                currentRegions[reg].GetWorldObjects().Add(b);
            }
        }
예제 #4
0
        static void EntityLogic(object sender, ElapsedEventArgs e)
        {
            if (GameState.CurrentState == GameState.GameStates.Paused || Screen.WindowOpen)
            {
                WorldData.interChar.Visible = false;
                return;
            }
            if (Save.SaveData.GameSettings.coOp && !Net.SessionManager.isHost)
            {
                return;
            }

            interactableObject = nulled;
            lock (WorldData.currentRegions) {
                foreach (World.Regions.RegionBase l in WorldData.currentRegions.Values)
                {
                    foreach (WorldObjectBase o in l.GetWorldObjects())
                    {
                        if (o is Entities.IEffectable en)
                        {
                            en.EffectTick();
                        }
                        if (o is World.Entities.StandardMob sn)
                        {
                            sn.AITick();
                        }

                        float dist = ObjectDistance(o, WorldData.player);
                        if (dist <= interactionDistance)
                        {
                            if (o is IInteractable)
                            {
                                if (interactableObject == null || dist < ObjectDistance(interactableObject, WorldData.player))
                                {
                                    interactableObject = o;
                                }
                            }
                        }
                    }
                }
            }
            if (interactableObject == null || interactableObject.Equals(nulled))
            {
                interactableObject = null;
            }
            if (interactableObject != null)
            {
                WorldData.interChar.SetScreenPosition(interactableObject.worldX, interactableObject.worldY + 15f);
                WorldData.interChar.Visible = true;
            }
            else
            {
                WorldData.interChar.Visible = false;
            }
        }
예제 #5
0
파일: EventAspect.cs 프로젝트: FizzyP/Iffy
 public static EventCause getEventCause(WorldObjectBase obj)
 {
     if (!obj.hasAttribute(kEventKey))
     {
         return(null);
     }
     else
     {
         return((EventCause)obj [kEventKey]);
     }
 }
예제 #6
0
 public static MapLocationState getMapLocationState(WorldObjectBase obj)
 {
     if (!obj.hasAttribute(kMapLocationKey))
     {
         return(null);
     }
     else
     {
         return(((MapLocationCause)obj [kMapLocationKey]).Value);
     }
 }
예제 #7
0
        public static WorldObjectBase imbue(WorldObjectBase obj, IntVector3 gridPosition, World world)
        {
            var initialState = new MapLocationState();

            initialState.position = gridPosition;
            initialState.velocity = new Vector3(0, 0, 0);
            initialState.world    = world;

            obj[kMapLocationKey] = new MapLocationCause(initialState);
            return(obj);
        }
예제 #8
0
 /// <summary>
 /// Removes a given WorldObject from the region it belongs to
 /// </summary>
 /// <param name="b"></param>
 public static void RemoveObject(WorldObjectBase b)
 {
     if (b == null)
     {
         return;
     }
     lock (currentRegions) {
         RegionBase ba = GetRegion(b.worldX, b.worldY);
         if (ba != null && ba.GetWorldObjects().Contains(b))
         {
             ba.GetWorldObjects().Remove(b);
         }
     }
 }
예제 #9
0
        static void PhysicsLogic(object sender, ElapsedEventArgs e)
        {
            if (GameState.CurrentState == GameState.GameStates.Paused || Screen.WindowOpen)
            {
                return;
            }
            bool playerstuck = false;

            float[] contPos = new float[12];
            WorldData.player.quadPosition.CopyTo(contPos, 0);
            WorldObjectBase.ShiftPosition(contPos, WorldData.player.movementQueueX, WorldData.player.movementQueueY);
            lock (WorldData.currentRegions) {
                foreach (World.Regions.RegionBase l in WorldData.currentRegions.Values)
                {
                    foreach (WorldObjectBase o in l.GetWorldObjects())
                    {
                        if (o is ICollidable)                           //TODO: change collision to use line intersection instead of test points on the player
                        {
                            if (CheckIntersection(o.quadPosition, contPos[0], contPos[1]) ||
                                CheckIntersection(o.quadPosition, contPos[3], contPos[4]) ||
                                CheckIntersection(o.quadPosition, contPos[6], contPos[7]) ||
                                CheckIntersection(o.quadPosition, contPos[9], contPos[10]) ||
                                CheckIntersection(o.quadPosition, (contPos[0] + contPos[9]) / 2, contPos[1]) ||
                                CheckIntersection(o.quadPosition, contPos[0], (contPos[1] + contPos[4]) / 2) ||
                                CheckIntersection(o.quadPosition, (contPos[3] + contPos[6]) / 2, contPos[4]) ||
                                CheckIntersection(o.quadPosition, contPos[6], (contPos[7] + contPos[10]) / 2) ||
                                CheckIntersection(o.quadPosition, (contPos[0] + contPos[9]) / 2, (contPos[1] + contPos[10]) / 2))
                            {
                                playerstuck = true;
                            }
                        }
                    }
                }
            }
            if (!playerstuck)
            {
                Form1.AddOrthoUpdate(WorldData.player.UpdatePosition);
            }
            else
            {
                WorldData.player.movementQueueX = 0;
                WorldData.player.movementQueueY = 0;
            }
        }
예제 #10
0
        public static WorldObjectBase imbue(WorldObjectBase obj, PerceptionCause perception)
        {
            var objLoc = MapLocationAspect.getMapLocationState(obj);

            if (objLoc == null)
            {
                throw new Exception("Cannot imbue an object with perception if it has no physical location.");
            }

            //	Remember the hearing cause
            obj [kEventListeningKey] = perception;

            //	Hook it up to listen to the world
            EventCause worldEvents = EventAspect.getEventCause(objLoc.world);

            perception.addDependency(worldEvents);

            return(obj);
        }
예제 #11
0
파일: EventAspect.cs 프로젝트: FizzyP/Iffy
 public static WorldObjectBase imbue(WorldObjectBase obj)
 {
     obj[kEventKey] = new EventCause();
     return(obj);
 }
예제 #12
0
 public static WorldObjectBase imbue(WorldObjectBase obj, MapLocationState initialState)
 {
     obj[kMapLocationKey] = new MapLocationCause(initialState);
     return(obj);
 }
예제 #13
0
 /// <summary>
 /// Returns the distance from Object o to Object p
 /// </summary>
 /// <param name="o"></param>
 /// <param name="p"></param>
 /// <returns></returns>
 public static float ObjectDistance(WorldObjectBase o, WorldObjectBase p)
 {
     return((float)Math.Sqrt(Math.Pow(p.worldX - o.worldX, 2f) + Math.Pow(p.worldY - o.worldY, 2f)));
 }