Exemplo n.º 1
0
        public Task <IEnumerable <ObjectID> > GetNearbyObjects(WorldObjectEntity objectEntity, float distance)
        {
            VerifyExists();

            var result          = new HashSet <ObjectID>();
            var distanceSquared = distance * distance;

            foreach (var entity in objects)
            {
                var xPart = objectEntity.Position.X - entity.Position.X;
                var yPart = objectEntity.Position.Y - entity.Position.Y;

                xPart *= xPart;
                yPart *= yPart;

                if (xPart + yPart < distanceSquared)
                {
                    // don't return objectEntity's id
                    if (!entity.Equals(objectEntity))
                    {
                        result.Add(entity.Id);
                    }
                }
            }

            return(Task.FromResult <IEnumerable <ObjectID> >(result));
        }
 /// <summary>
 /// Makes the argument objectToMakeUnused marked as unused.  This method is generated to be used
 /// by generated code.  Use Destroy instead when writing custom code so that your code will behave
 /// the same whether your Entity is pooled or not.
 /// </summary>
 public static void MakeUnused(WorldObjectEntity objectToMakeUnused, bool callDestroy)
 {
     if (callDestroy)
     {
         objectToMakeUnused.Destroy();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a MovementUpdate for a PersistentObject.
        /// </summary>
        /// <param name="entity">Cannot be null</param>
        public MovementUpdate(WorldObjectEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            Position    = entity.Position;
            Orientation = entity.Orientation;
        }
        private static void FactoryInitialize()
        {
            const int numberToPreAllocate = 20;

            for (int i = 0; i < numberToPreAllocate; i++)
            {
                WorldObjectEntity instance = new WorldObjectEntity(mContentManagerName, false);
                mPool.AddToPool(instance);
            }
        }
Exemplo n.º 5
0
        public async Task RemoveObject(WorldObjectEntity objectEntity)
        {
            VerifyExists();

            var objectService    = GrainFactory.GetGrain <IObjectService>(0);
            var persistentObject = await objectService.GetObject(objectEntity.Id);

            await persistentObject.Unsubscribe(this);

            objects.Remove(objectEntity);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Converts the domain model into an entity.
        /// </summary>
        /// <returns>The entity.</returns>
        /// <param name="worldObject">WorldObject.</param>
        internal static WorldObjectEntity ToEntity(this WorldObject worldObject)
        {
            WorldObjectEntity worldObjectEntity = new WorldObjectEntity
            {
                Id            = worldObject.Id,
                Name          = worldObject.Name,
                Description   = worldObject.Description,
                MinimapColour = worldObject.MinimapColour.ToHexadecimal()
            };

            return(worldObjectEntity);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Converts the entity into a domain model.
        /// </summary>
        /// <returns>The domain model.</returns>
        /// <param name="worldObjectEntity">WorldObject entity.</param>
        internal static WorldObject ToDomainModel(this WorldObjectEntity worldObjectEntity)
        {
            WorldObject worldObject = new WorldObject
            {
                Id            = worldObjectEntity.Id,
                Name          = worldObjectEntity.Name,
                Description   = worldObjectEntity.Description,
                MinimapColour = ColourTranslator.FromHexadecimal(worldObjectEntity.MinimapColour)
            };

            return(worldObject);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Converts the domain model into an entity.
        /// </summary>
        /// <returns>The entity.</returns>
        /// <param name="worldObject">Model.</param>
        internal static WorldObjectEntity ToEntity(this WorldObject worldObject)
        {
            WorldObjectEntity worldObjectEntity = new WorldObjectEntity
            {
                Id          = worldObject.Id,
                Name        = worldObject.Name,
                Description = worldObject.Description,
                Command1    = worldObject.Command1,
                Command2    = worldObject.Command2,
                Type        = worldObject.Type.ToString()
            };

            return(worldObjectEntity);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Converts the entity into a domain model.
        /// </summary>
        /// <returns>The domain model.</returns>
        /// <param name="worldObjectEntity">Model entity.</param>
        internal static WorldObject ToDomainModel(this WorldObjectEntity worldObjectEntity)
        {
            WorldObject worldObject = new WorldObject
            {
                Id          = worldObjectEntity.Id,
                Name        = worldObjectEntity.Name,
                Description = worldObjectEntity.Description,
                Command1    = worldObjectEntity.Command1,
                Command2    = worldObjectEntity.Command2,
                Type        = (WorldObjectType)Enum.Parse(typeof(WorldObjectType), worldObjectEntity.Type)
            };

            return(worldObject);
        }
        public static WorldObjectEntity CreateNew(Layer layer)
        {
            if (string.IsNullOrEmpty(mContentManagerName))
            {
                throw new System.Exception("You must first initialize the factory to use it. You can either add PositionedObjectList of type WorldObjectEntity (the most common solution) or call Initialize in custom code");
            }
            WorldObjectEntity instance = null;

            instance = new WorldObjectEntity(mContentManagerName, false);
            instance.AddToManagers(layer);
            if (mScreenListReference != null)
            {
                mScreenListReference.Add(instance);
            }
            if (EntitySpawned != null)
            {
                EntitySpawned(instance);
            }
            return(instance);
        }
Exemplo n.º 11
0
        private void PerformCollision()
        {
            foreach (var player in PlayerList)
            {
                solidCollision.CollideAgainstSolid(player);

                player.CollideAgainstBounce(AboveWaterCollision, 0, 1, 0);

                objectCollidingWith = null;
                player.ObjectsToPerformCurrencyTransactionOn.Clear();

                foreach (var worldObject in WorldObjectEntityList)
                {
                    worldObject.SetIsVisible(true);
                    if (player.CollideAgainst(worldObject))
                    {
                        objectCollidingWith = worldObject;
                        worldObject.SetIsVisible(false);
                        break;
                    }
                }

                foreach (var disablerEntity in DisablerEntityList)
                {
                    if (player.CollideAgainst(disablerEntity))
                    {
                        string nameToDisable = disablerEntity.ObjectToDisable;

                        var matchingWorldObjectEntity = WorldObjectEntityList.FirstOrDefault(item => item.Name == nameToDisable);

                        if (matchingWorldObjectEntity != null)
                        {
                            matchingWorldObjectEntity.Enabled = false;
                        }
                        else
                        {
                            throw new InvalidOperationException($"Could not find a MoveToScreen entity with the name {nameToDisable}");
                        }
                    }
                }

                if (!isTransitioning)
                {
                    foreach (var enablerEntity in EnablerEntityList)
                    {
                        if (player.CollideAgainst(enablerEntity))
                        {
                            string nameToEnable = enablerEntity.ObjectToEnable;

                            var foundMoveEntity = MoveToScreenEntityList.FirstOrDefault(item => item.Name == nameToEnable);

                            var foundMatchingSafeZoneEntity = SafeZoneList.FirstOrDefault(item => item.Name == nameToEnable);

                            if (foundMoveEntity != null)
                            {
                                foundMoveEntity.Enabled = true;
                            }
                            else if (foundMatchingSafeZoneEntity != null)
                            {
                                foundMatchingSafeZoneEntity.Enabled = true;
                            }
                            else
                            {
                                throw new InvalidOperationException($"Could not find a MoveToScreen or SafeZone entity with the name {nameToEnable}");
                            }
                        }
                    }

                    foreach (var moveEntity in MoveToScreenEntityList)
                    {
                        if (moveEntity.Enabled && player.CollideAgainst(moveEntity))
                        {
                            isTransitioning = true;
                            GlobalData.TotalCurrencyCollected = player.TotalCurrencyCollected;
                            this.GameScreenGumRuntime.InterpolateTo(FadeoutCategory.Dark, FadeOutTime, InterpolationType.Linear, Easing.In);
                            this.Call(() => MoveToScreen($"Anfloga.Screens.{moveEntity.Screen}"))
                            .After(FadeOutTime);
                        }
                    }
                }

                foreach (var disabler in this.SafeZoneDisablerList)
                {
                    if (player.CollideAgainst(disabler))
                    {
                        arePlayerBuiltSafeZonesEnabled = false;
                    }
                }
                // We will assume the player is not in a replenish zone, then set to replenish if they are colliding with one.
                player.CurrentExplorationState = ExplorationState.Consume;
                foreach (var safeZone in SafeZoneList)
                {
                    if (player.CollideAgainst(safeZone))
                    {
                        if (safeZone.IsActive)
                        {
                            if ((arePlayerBuiltSafeZonesEnabled || safeZone.BuiltByPlayer == false) && safeZone.Enabled)
                            {
                                player.CurrentExplorationState = ExplorationState.Replenish;
                            }
                        }
                        else
                        {
                            //Let the playe know they can activate the safe zone?
                            player.ObjectsToPerformCurrencyTransactionOn.Add(safeZone);
                        }
                    }
                }
                foreach (var mineral in MineralDepositList)
                {
                    if (player.CollideAgainst(mineral))
                    {
                        player.ObjectsToPerformCurrencyTransactionOn.Add(mineral);
                    }
                }

                foreach (var darknessTrigger in DarknessTriggerList)
                {
                    if (player.CollideAgainst(darknessTrigger) && lastDarknessTriggerCollidedAgainst != darknessTrigger)
                    {
                        lastDarknessTriggerCollidedAgainst = darknessTrigger;
                        RespondToDarknessTriggerCollision(darknessTrigger);
                    }
                }
            }
        }
Exemplo n.º 12
0
        public void Update(bool pressedDialogButton, WorldObjectEntity worldEntityCollidingWith)
        {
            switch (currentDialogShownState)
            {
            case DialogShownState.Hidden:

                if (worldEntityCollidingWith != null)
                {
                    bool shouldSkipConsumedDialog = worldEntityCollidingWith.IsConsumable && worldEntityCollidingWith.HasBeenConsumed;

                    bool shouldShow = false;

                    if (!shouldSkipConsumedDialog && worldEntityCollidingWith.Enabled)
                    {
                        if (worldEntityCollidingWith.AutomaticDialogDisplay)
                        {
                            shouldShow = true;
                            currentDialogShownState = DialogShownState.AutomaticallyShown;
                        }
                        else if (pressedDialogButton)
                        {
                            shouldShow = true;
                            currentDialogShownState = DialogShownState.ExplicitlyShown;
                        }

                        if (shouldShow)
                        {
                            DialogBox.Visible = true;
                            //We will set HasBeenConsumed if it is marked as consumable.
                            worldEntityCollidingWith.HasBeenConsumed = worldEntityCollidingWith.IsConsumable;
                            DialogBox.Text = LocalizationManager.Translate(worldEntityCollidingWith.DialogKey);
                            worldEntityCollidingWith.TimeDialogShown = ScreenManager.CurrentScreen.PauseAdjustedCurrentTime;
                            entityShowingDialog = worldEntityCollidingWith;
                        }
                    }
                }

                break;

            case DialogShownState.AutomaticallyShown:
                bool shouldClose = false;
                if (entityShowingDialog.AutomaticDismissTime > 0)
                {
                    shouldClose = ScreenManager.CurrentScreen.PauseAdjustedSecondsSince(entityShowingDialog.TimeDialogShown) >
                                  entityShowingDialog.AutomaticDismissTime;
                }
                else if (worldEntityCollidingWith != entityShowingDialog)
                {
                    // user moved out of the collision area, so hide it
                    shouldClose = true;
                }

                if (shouldClose)
                {
                    CloseDialog();
                }

                // Do we want the user to be able to automatically close out the dialog?

                break;

            case DialogShownState.ExplicitlyShown:
                if (pressedDialogButton)
                {
                    CloseDialog();
                }
                break;
            }
        }
Exemplo n.º 13
0
 private void CloseDialog()
 {
     entityShowingDialog     = null;
     DialogBox.Visible       = false;
     currentDialogShownState = DialogShownState.Hidden;
 }
 /// <summary>
 /// Makes the argument objectToMakeUnused marked as unused.  This method is generated to be used
 /// by generated code.  Use Destroy instead when writing custom code so that your code will behave
 /// the same whether your Entity is pooled or not.
 /// </summary>
 public static void MakeUnused(WorldObjectEntity objectToMakeUnused)
 {
     MakeUnused(objectToMakeUnused, true);
 }