示例#1
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            if (item.HasValueTag("ammo") == false || item.HasValueTag("amount") == false)
            {
                hydratedElement = null;
                return(false);
            }

            var weaponTypeName = item.GetTagValue("ammo");
            var weaponType     = Type.GetType(weaponTypeName, false, true);

            if (weaponType == null)
            {
                weaponType = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(Weapon)) && t.Name == weaponTypeName).SingleOrDefault();
            }

            if (weaponType == null)
            {
                weaponType = Assembly.GetEntryAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(Weapon)) && t.Name == weaponTypeName).SingleOrDefault();
            }

            if (weaponType == null)
            {
                throw new ArgumentException("Could not resolve weapon type: " + weaponTypeName);
            }

            var amount = int.Parse(item.GetTagValue("amount"));

            var weapon = Activator.CreateInstance(weaponType) as Weapon;

            weapon.AmmoAmount = amount;

            hydratedElement = new LooseWeapon(weapon);
            return(true);
        }
示例#2
0
 public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
 {
     hydratedElement = new Wall()
     {
         Pen = new ConsoleCharacter(item.Symbol, item.FG, item.BG)
     };
     return(true);
 }
示例#3
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            if (item.Tags.Contains("main-character") == false)
            {
                hydratedElement = null;
                return(false);
            }

            hydratedElement = new MainCharacter();
            return(true);
        }
示例#4
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            if (item.HasValueTag("cutscene") == false)
            {
                hydratedElement = null;
                return(false);
            }

            var scene = SceneFactory.CreateInstance <ICutScene>(item.GetTagValue("cutscene"));

            hydratedElement = TimeFunction.Create(null, init: scene.Start);
            return(true);
        }
示例#5
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            var waypointTag = item.Tags.Where(t => t.Equals("waypoint")).SingleOrDefault();

            if (waypointTag == null)
            {
                hydratedElement = null;
                return(false);
            }

            hydratedElement = new Waypoint();
            return(true);
        }
示例#6
0
 public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
 {
     if (item.FG != ConsoleColor.Red)
     {
         hydratedElement = null;
         return(false);
     }
     else
     {
         hydratedElement = new FlammableLetter()
         {
             Symbol = new ConsoleCharacter(item.Symbol, ConsoleColor.White, item.BG)
         };
         return(true);
     }
 }
示例#7
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            if (item.HasValueTag("trigger") == false)
            {
                hydratedElement = null;
                return(false);
            }

            var range   = item.HasValueTag("range") && float.TryParse(item.GetTagValue("range"), out float result) ? result : 5f;
            var trigger = new Trigger()
            {
                Id = item.GetTagValue("trigger"), Range = range
            };

            hydratedElement = trigger;
            return(true);
        }
示例#8
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            if (item.HasValueTag("destination") == false)
            {
                hydratedElement = null;
                return(false);
            }

            hydratedElement = new Portal();

            try
            {
                (hydratedElement as Portal).LevelId = item.GetTagValue("destination");
            }
            catch (Exception ex)
            {
            }
            return(true);
        }
示例#9
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            if (item.HasSimpleTag("friendly") == false)
            {
                hydratedElement = null;
                return(false);
            }

            var friendly = new Friendly();

            friendly.Inventory.Items.Add(new Pistol()
            {
                AmmoAmount = 100, HealthPoints = 10,
            });
            hydratedElement = friendly;
            new Bot(friendly, new List <IBotStrategy> {
                new AvoidEnemies()
            });
            return(true);
        }
示例#10
0
        private int CountAndRemoveDoorsToRight(List <LevelItem> items, LevelItem leftMost)
        {
            var x = leftMost.X + 1;

            var count = 0;

            while (true)
            {
                var adjacentItem = items.Where(i => i != leftMost && i.Symbol == 'd' && i.X == x && i.Y == leftMost.Y).SingleOrDefault();
                if (adjacentItem == null)
                {
                    break;
                }

                adjacentItem.Ignore = true;
                count++;
                x++;
            }

            return(count);
        }
示例#11
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            if (item.Symbol == 'd' && item.HasSimpleTag("door"))
            {
                var isDoorAboveMe    = allItems.Where(i => i != item && i.Symbol == 'd' && i.Y == item.Y - 1 && item.X == item.X).Any();
                var isDoorToLeftOfMe = allItems.Where(i => i != item && i.Symbol == 'd' && i.X == item.X - 1 && item.Y == item.Y).Any();

                if (isDoorAboveMe == false && isDoorToLeftOfMe == false)
                {
                    var bigDoor = new Door();
                    hydratedElement = bigDoor;

                    var rightCount = CountAndRemoveDoorsToRight(allItems, item);
                    var belowCount = CountAndRemoveDoorsBelow(allItems, item);

                    if (rightCount > 0)
                    {
                        item.Width           = rightCount + 1;
                        bigDoor.ClosedBounds = PowerArgs.Cli.Physics.RectangularF.Create(item.X, item.Y, item.Width, item.Height);
                        bigDoor.OpenBounds   = PowerArgs.Cli.Physics.RectangularF.Create(bigDoor.ClosedBounds.Left + item.Width, bigDoor.ClosedBounds.Top, item.Width, item.Height);
                    }
                    else if (belowCount > 0)
                    {
                        item.Height          = belowCount + 1;
                        bigDoor.ClosedBounds = PowerArgs.Cli.Physics.RectangularF.Create(item.X, item.Y, item.Width, item.Height);
                        bigDoor.OpenBounds   = PowerArgs.Cli.Physics.RectangularF.Create(bigDoor.ClosedBounds.Left, bigDoor.ClosedBounds.Top + item.Height, item.Width, item.Height);
                    }
                    else
                    {
                        throw new Exception("Lonely door");
                    }


                    return(true);
                }
            }

            hydratedElement = null;
            return(false);
        }
示例#12
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            var enemyTag = item.Tags.Where(testc => testc.Equals("enemy")).SingleOrDefault();

            if (enemyTag == null)
            {
                hydratedElement = null;
                return(false);
            }

            var enemy = new Enemy();

            enemy.Inventory.Items.Add(new Pistol()
            {
                AmmoAmount = 100, HealthPoints = 10,
            });
            hydratedElement = enemy;
            new Bot(enemy, new List <IBotStrategy> {
                new FireAtWill(), new MoveTowardsEnemy()
            });
            return(true);
        }
示例#13
0
        private int CountAndRemoveDoorsBelow(List <LevelItem> items, LevelItem topMost)
        {
            var y = topMost.Y + 1;

            var count = 0;

            while (true)
            {
                var adjacentItem = items.Where(i => i != topMost && i.Symbol == 'd' && i.Y == y && i.X == topMost.X).SingleOrDefault();

                if (adjacentItem == null)
                {
                    break;
                }

                adjacentItem.Ignore = true;
                count++;
                y++;
            }

            return(count);
        }
示例#14
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            var text = string.Empty;

            if (item.HasSimpleTag(EffectName) || item.HasValueTag(EffectName))
            {
                for (var x = 0; x < 500; x++)
                {
                    var next = allItems.Where(i => i.X == item.X + x && i.Y == item.Y).FirstOrDefault();
                    if (next != null)
                    {
                        next.Ignore = true;
                        text       += next.Symbol;
                    }
                    else
                    {
                        break;
                    }
                }


                var delay = item.HasValueTag(EffectName) && int.TryParse(item.GetTagValue(EffectName), out int result) ? result : 0;
                var stay  = item.HasValueTag("stay") && int.TryParse(item.GetTagValue("stay"), out int stayResult) ? stayResult : 10000;


                var effect = SceneFactory.CreateInstance <TextEffect>(EffectName);
                effect.Options = new TextEffectOptions()
                {
                    Left = item.X,
                    Top  = item.Y,
                    Text = text,
                    DurationMilliseconds = stay,
                };

                if (item.HasValueTag("triggerId") == false)
                {
                    hydratedElement = TimeFunction.CreateDelayed(delay, null, init: effect.Start);
                    return(true);
                }
                else
                {
                    hydratedElement = TimeFunction.Create(null, () =>
                    {
                        var id      = item.GetTagValue("triggerId");
                        var trigger = SpaceTime.CurrentSpaceTime.Elements.WhereAs <Trigger>().Where(t => t.Id == id).SingleOrDefault();

                        if (trigger == null)
                        {
                            throw new ArgumentException("No trigger with id: " + id);
                        }

                        trigger.Fired.SubscribeOnce((notused) =>
                        {
                            effect.Start();
                        });
                    });

                    return(true);
                }
            }

            hydratedElement = null;
            return(false);
        }