Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        public void Loot(AdventureEntity entity)
        {
            // only allow mogwais to loot
            if (!(this is Mogwai.Mogwai mogwai))
            {
                return;
            }

            if (entity.LootState == LootState.None ||
                entity.LootState == LootState.Looted)
            {
                return;
            }

            var activity = ActivityLog.Create(ActivityLog.ActivityType.Loot, ActivityLog.ActivityState.None, new int[] { }, null);

            Mogwai.Mogwai.History.Add(LogType.Info, activity);
            Adventure?.Enqueue(AdventureLog.Info(this, entity, activity));

            if (entity.Treasure != null)
            {
                activity = ActivityLog.Create(ActivityLog.ActivityType.Treasure, ActivityLog.ActivityState.Success, new int[] { }, null);
                Mogwai.Mogwai.History.Add(LogType.Info, activity);
                Adventure?.Enqueue(AdventureLog.Info(this, entity, activity));
                mogwai.AddGold(entity.Treasure.Gold);
            }
            else
            {
                activity = ActivityLog.Create(ActivityLog.ActivityType.Treasure, ActivityLog.ActivityState.Fail, new int[] { }, null);
                Mogwai.Mogwai.History.Add(LogType.Info, activity);
                Adventure?.Enqueue(AdventureLog.Info(this, entity, activity));
            }

            entity.LootState = LootState.Looted;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Move an entity
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="destination"></param>
        public void MoveEntity(Combatant entity, Coord destination)
        {
            if (!WalkabilityMap[destination])
            {
                throw new Exception();
            }

            if (EntityMap[entity.Coordinate] == null)
            {
                throw new Exception();
            }


            EntityMap[entity.Coordinate].Remove(entity);
            WalkabilityMap[entity.Coordinate] = EntityMap[entity.Coordinate].IsPassable;

            // clean up seems not needed
            //if (!EntityMap[entity.Coordinate].Has<AdventureEntity>())
            //{
            //    EntityMap[entity.Coordinate] = null;
            //}

            if (EntityMap[destination] == null)
            {
                EntityMap[destination] = new AdventureEntityContainer();
            }
            EntityMap[destination].Add(entity);
            WalkabilityMap[destination] = EntityMap[destination].IsPassable;

            entity.Coordinate = destination;

            entity.FovCoords = CalculateFoV(entity.Coordinate, entity is Mogwai);

            Adventure.Enqueue(AdventureLog.EntityMoved(entity, destination));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="spellCast"></param>
        /// <returns></returns>
        private bool Cast(SpellCast spellCast)
        {
            var spell = spellCast.Spell;

            if (spellCast.Target is Entity target)
            {
                // TODO: https://github.com/WorldOfMogwais/WoMNetCore/issues/22
                var concentrateRoll = 10;

                Adventure.Enqueue(AdventureLog.Info(this, target, ActivityLog.Create(ActivityLog.ActivityType.Cast, ActivityLog.ActivityState.Init, concentrateRoll, spell)));

                if (concentrateRoll > 1 && concentrateRoll > spell.Level)
                {
                    Adventure.Enqueue(AdventureLog.Info(this, target, ActivityLog.Create(ActivityLog.ActivityType.Cast, ActivityLog.ActivityState.Success, concentrateRoll, spell)));
                    spell.SpellEffect(this, target);
                }
                else
                {
                    Adventure.Enqueue(AdventureLog.Info(this, target, ActivityLog.Create(ActivityLog.ActivityType.Cast, ActivityLog.ActivityState.Fail, concentrateRoll, spell)));
                }

                Adventure.Enqueue(AdventureLog.Attacked(this, target));

                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="damageAmount"></param>
        /// <param name="damageType"></param>
        public void Damage(int damageAmount, DamageType damageType)
        {
            // no damage return or same for dead entities
            if (damageAmount <= 0 || IsDead)
            {
                return;
            }

            var activity = ActivityLog.Create(ActivityLog.ActivityType.Damage, ActivityLog.ActivityState.None, new int[] { damageAmount, (int)damageType }, null);

            Mogwai.Mogwai.History.Add(LogType.Info, activity);
            Adventure?.Enqueue(AdventureLog.Info(this, null, activity));
            CurrentHitPoints -= damageAmount;

            if (!CanAct)
            {
                activity = ActivityLog.Create(ActivityLog.ActivityType.HealthState, ActivityLog.ActivityState.None, new int[] { (int)HealthState }, null);
                Mogwai.Mogwai.History.Add(LogType.Info, activity);
                Adventure?.Enqueue(AdventureLog.Info(this, null, activity));
            }

            if (IsDead)
            {
                activity = ActivityLog.Create(ActivityLog.ActivityType.HealthState, ActivityLog.ActivityState.None, new int[] { (int)HealthState }, null);
                Mogwai.Mogwai.History.Add(LogType.Info, activity);
                Adventure?.Enqueue(AdventureLog.Info(this, null, activity));

                Map.DeadEntity(this);
            }
        }
        public async Task PostAdventureLogTest(string url)
        {
            // Arrange
            var client = _factory.CreateClient();

            var itemToSend = new AdventureLog
            {
                UserId   = null,
                LogTitle = "Session 22: More Stuff",
                LogBody  = "<p><b>The elf jumped over the lazy dwarf.</b></p>"
            };
            var sentContent = JsonConvert.SerializeObject(itemToSend);

            string beforeLogCountQueryResult = _queryHelper.SelectQuery("SELECT TOP 1 HistoricalLogCount FROM HistoricalAdventureLogCounts", "HistoricalLogCount");
            int    beforeLogCount            = int.Parse(beforeLogCountQueryResult);

            // Act
            var send = await client.PostAsync(url, new StringContent(sentContent, Encoding.UTF8, "application/json"));

            string afterLogCountQueryResult = _queryHelper.SelectQuery("SELECT TOP 1 HistoricalLogCount FROM HistoricalAdventureLogCounts", "HistoricalLogCount");
            int    afterLogCount            = int.Parse(afterLogCountQueryResult);

            string createdLogTitleQueryResult = _queryHelper.SelectQuery($"SELECT LogTitle FROM AdventureLogs WHERE AdventureLogID = {afterLogCount}", "LogTitle");
            string createdLogBodyQueryResult  = _queryHelper.SelectQuery($"SELECT LogBody FROM AdventureLogs WHERE AdventureLogID = {afterLogCount}", "LogBody");

            // Assert
            send.EnsureSuccessStatusCode(); // Status Code 200-299
            Assert.Equal("application/json; charset=utf-8", send.Content.Headers.ContentType.ToString());
            Assert.Equal(itemToSend.LogTitle, createdLogTitleQueryResult);
            Assert.Equal(itemToSend.LogBody, createdLogBodyQueryResult);
            Assert.NotEqual(beforeLogCount, afterLogCount);
        }
        public AdventureLog SelectAdventureLogQuery(int id)
        {
            string       query        = $"SELECT * FROM AdventureLogs WHERE AdventureLogID = {id}";
            AdventureLog adventureLog = new AdventureLog();

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                SqlCommand command = new SqlCommand(query, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        if (reader.HasRows)
                        {
                            adventureLog = new AdventureLog()
                            {
                                AdventureLogID = id,
                                UserId         = reader["UserId"].ToString(),
                                LogTitle       = reader["LogTitle"].ToString(),
                                LogBody        = reader["LogBody"].ToString(),
                                LogDate        = DateTime.Parse(reader["LogDate"].ToString())
                            };
                        }
                    }
                }
                catch (Exception exc)
                {
                    //_logger.AddSystemLog($"Failed to read query results: {exc}");
                }

                return(adventureLog);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Add entity to the map
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public void AddEntity(AdventureEntity entity, int x, int y)
        {
            // can't add an entity to invalid position
            if (!WalkabilityMap[x, y])
            {
                throw new Exception();
            }

            if (!entity.IsPassable)
            {
                WalkabilityMap[x, y] = false;
            }

            entity.Map        = this;
            entity.Coordinate = new Coord(x, y);

            if (EntityMap[x, y] == null)
            {
                EntityMap[x, y] = new AdventureEntityContainer();
            }

            EntityMap[x, y].Add(entity);

            if (entity is Combatant combatant)
            {
                // calculate fov
                combatant.FovCoords = CalculateFoV(entity.Coordinate, entity is Mogwai);
            }

            // add entity to list
            Entities.Add(entity);

            Adventure.Enqueue(AdventureLog.EntityCreated(entity));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <AdventureLog> > PostAdventureLog([FromBody] AdventureLog adventureLog)
        {
            try
            {
                adventureLog.UserId = User.FindFirstValue(ClaimTypes.NameIdentifier);

                if (string.IsNullOrWhiteSpace(adventureLog.LogTitle))
                {
                    adventureLog.LogTitle = "Untitled";
                }
                if (string.IsNullOrWhiteSpace(adventureLog.LogBody))
                {
                    adventureLog.LogBody = "Nothing seems to be here!";
                }

                adventureLog = Utilities.NewCreateDateFormatted(adventureLog);

                await _context.AdventureLogs.AddAsync(adventureLog);

                _context.SaveChanges();

                return(CreatedAtAction("GetAdventureLog", new { id = adventureLog.AdventureLogID }, adventureLog));
            }
            catch (Exception exc)
            {
                _logController.AddSystemLog($"ERROR: {exc.Message}");
                return(BadRequest());
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="weaponAttack"></param>
        /// <returns></returns>
        private void Attack(WeaponAttack weaponAttack)
        {
            var attackTimes = weaponAttack.ActionType == ActionType.Full ? BaseAttackBonus.Length : 1;
            var weapon      = weaponAttack.Weapon;
            var target      = weaponAttack.Target as Entity;

            //Console.WriteLine($"{Name}: is attacking {attackTimes} times");

            // all attacks are calculated
            Parallel.For(0, attackTimes, (attackIndex, state) =>
            {
                // break when target is null or dead, no more attacks on dead monsters.
                if (target == null || target.IsDead)
                {
                    state.Break();
                }

                var attackRolls = AttackRolls(attackIndex, weapon.CriticalMinRoll);
                var attack      = AttackRoll(attackRolls, target.ArmorClass, out var criticalCounts);

                Adventure.Enqueue(AdventureLog.Info(this, target,
                                                    ActivityLog.Create(ActivityLog.ActivityType.Attack, ActivityLog.ActivityState.Init,
                                                                       new int[] { attackIndex, attack, criticalCounts }, weaponAttack)));

                if (attack > target.ArmorClass || criticalCounts > 0)
                {
                    var damage         = DamageRoll(weapon, Dice);
                    var criticalDamage = 0;
                    if (criticalCounts > 0)
                    {
                        for (var i = 0; i < weapon.CriticalMultiplier - 1; i++)
                        {
                            criticalDamage += DamageRoll(weapon, Dice);
                        }
                    }

                    Adventure.Enqueue(AdventureLog.Info(this, target,
                                                        ActivityLog.Create(ActivityLog.ActivityType.Attack, ActivityLog.ActivityState.Success,
                                                                           new int[]
                    {
                        attackIndex, attack, criticalCounts, damage, criticalDamage, (int)DamageType.Weapon
                    }, weaponAttack)));
                    target.Damage(damage + criticalDamage, DamageType.Weapon);
                }
                else
                {
                    Adventure.Enqueue(AdventureLog.Info(this, target,
                                                        ActivityLog.Create(ActivityLog.ActivityType.Attack, ActivityLog.ActivityState.Fail,
                                                                           new int[] { attackIndex, attack, criticalCounts }, weaponAttack)));
                }

                Adventure.Enqueue(AdventureLog.Attacked(this, target));
            });
        }
Ejemplo n.º 10
0
 private void Awake()
 {
     if (Instance == null)
     {
         DontDestroyOnLoad(gameObject);
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
 }
Ejemplo n.º 11
0
        public static AdventureLog NewCreateDateFormatted(AdventureLog adventureLog)
        {
            DateTime createTime    = DateTime.Now;
            string   stringVersion = createTime.ToString("M/d/yyyy");

            createTime = DateTime.Parse(stringVersion);

            adventureLog.DisplayLogDate = stringVersion;
            adventureLog.LogDate        = createTime;

            return(adventureLog);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Passive level up, includes for example hit point roles.
        /// </summary>
        private void LevelUp()
        {
            var activity = ActivityLog.Create(ActivityLog.ActivityType.Level, ActivityLog.ActivityState.None, new int[] { CurrentLevel }, null);

            History.Add(LogType.Info, activity);
            Adventure?.Enqueue(AdventureLog.Info(this, null, activity));

            // level up grant free revive
            SpecialAction(SpecialType.Reviving);

            // level up grant free heal
            SpecialAction(SpecialType.Heal);
        }
Ejemplo n.º 13
0
        public async Task <ActionResult <AdventureLog> > DeleteAdventureLog(int id)
        {
            AdventureLog adventureLog = await _context.AdventureLogs.FindAsync(id);

            if (adventureLog == null || adventureLog.UserId != User.FindFirstValue(ClaimTypes.NameIdentifier))
            {
                return(NotFound());
            }

            _context.AdventureLogs.Remove(adventureLog);
            await _context.SaveChangesAsync();

            return(adventureLog);
        }
Ejemplo n.º 14
0
        /// <inheritdoc />
        public override void AddGold(int gold)
        {
            var activity = ActivityLog.Create(ActivityLog.ActivityType.Gold, ActivityLog.ActivityState.None, new int[] { gold }, null);

            History.Add(LogType.Info, activity);
            if (Adventure != null)
            {
                Adventure.Enqueue(AdventureLog.Info(this, null, activity));
                Adventure.AdventureStats[AdventureStats.Gold] = Adventure.AdventureStats[AdventureStats.Gold] + gold;
            }


            Wealth.Gold += gold;
        }
Ejemplo n.º 15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        public void DeadEntity(Combatant entity)
        {
            if (EntityMap[entity.Coordinate] == null)
            {
                throw new Exception();
            }

            // dead bodies are passable
            entity.IsPassable = true;

            WalkabilityMap[entity.Coordinate] = EntityMap[entity.Coordinate].IsPassable;

            Adventure.Enqueue(AdventureLog.Died(entity));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Remove entity from the map
        /// </summary>
        /// <param name="entity"></param>
        public void RemoveEntity(Combatant entity)
        {
            if (EntityMap[entity.Coordinate] == null)
            {
                throw new Exception();
            }

            if (!entity.IsPassable)
            {
                WalkabilityMap[entity.Coordinate] = true;
            }

            EntityMap[entity.Coordinate] = null;

            // remove entity to list
            Entities.Remove(entity);

            Adventure.Enqueue(AdventureLog.EntityRemoved(entity));
        }
Ejemplo n.º 17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="healAmount"></param>
        /// <param name="healType"></param>
        public void Heal(int healAmount, HealType healType)
        {
            var missingHealth = MaxHitPoints - CurrentHitPoints;

            if (missingHealth <= 0 || healAmount <= 0)
            {
                return;
            }

            if (missingHealth < healAmount)
            {
                healAmount = missingHealth;
            }
            var activity = ActivityLog.Create(ActivityLog.ActivityType.Heal, ActivityLog.ActivityState.None, new int[] { healAmount, (int)healType }, null);

            Mogwai.Mogwai.History.Add(LogType.Info, activity);
            Adventure?.Enqueue(AdventureLog.Info(this, null, activity));

            CurrentHitPoints += healAmount;
        }
Ejemplo n.º 18
0
        /// <inheritdoc />
        public override void AddExp(double exp, Monster.Monster monster = null)
        {
            var activity = ActivityLog.Create(ActivityLog.ActivityType.Exp, ActivityLog.ActivityState.None, new int[] { (int)exp }, monster);

            History.Add(LogType.Info, activity);
            if (Adventure != null)
            {
                Adventure.Enqueue(AdventureLog.Info(this, null, activity));
                Adventure.AdventureStats[AdventureStats.Experience] = Adventure.AdventureStats[AdventureStats.Experience] + exp;
            }

            Exp += exp;

            while (Exp >= XpToLevelUp)
            {
                CurrentLevel += 1;
                LevelShifts.Add(_currentShift.Height);
                LevelUp();
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="classType"></param>
        private void LevelClass(ClassType classType)
        {
            if (!CanLevelClass(out _))
            {
                Log.Warn("Not allowed class leveling action.");
                return;
            }

            var classes = Classes.FirstOrDefault(p => p.ClassType == classType);

            if (Classes.Count == 0 || classes == null)
            {
                Classes.Insert(0, Model.Classes.Classes.GetClasses(classType));
            }
            else if (Classes.Remove(classes))
            {
                Classes.Insert(0, classes);
            }

            var classesLevels = Classes.Sum(p => p.ClassLevel);

            // do the class level up
            Classes[0].ClassLevelUp();

            var dice = Shifts[LevelShifts[classesLevels]].MogwaiDice;

            // level class now
            LevelClass(dice);

            // initial class level
            if (classesLevels == 0)
            {
                AddGold(dice.Roll(Classes[0].WealthDiceRollEvent));
            }

            var activity = ActivityLog.Create(ActivityLog.ActivityType.LevelClass, ActivityLog.ActivityState.None, new int[] { (int)classType }, null);

            History.Add(LogType.Info, activity);
            Adventure?.Enqueue(AdventureLog.Info(this, null, activity));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> PutAdventureLog(int id, AdventureLog sentAdventureLog)
        {
            string       requestingUser = User.FindFirstValue(ClaimTypes.NameIdentifier);
            AdventureLog adventureLog   = await _context.AdventureLogs.FindAsync(id);

            if (id != sentAdventureLog.AdventureLogID || adventureLog.UserId != requestingUser)
            {
                return(BadRequest());
            }
            if (!string.IsNullOrWhiteSpace(sentAdventureLog.LogTitle))
            {
                adventureLog.LogTitle = sentAdventureLog.LogTitle;
            }
            if (!string.IsNullOrWhiteSpace(sentAdventureLog.LogBody))
            {
                adventureLog.LogBody = sentAdventureLog.LogBody;
            }

            _context.Entry(adventureLog).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AdventureLogExists(id))
                {
                    _logController.AddSystemLog($"WARNING: User {requestingUser} has caused a DbUpdateConcurrencyException");
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task PutAdventureLogTest(string url)
        {
            //Arrange
            var    client = _factory.CreateClient();
            string adventureLogIdResult = _queryHelper.SelectQuery("SELECT TOP 1 AdventureLogID FROM AdventureLogs ORDER BY AdventureLogID DESC", "AdventureLogID");
            int    adventureLogId       = int.Parse(adventureLogIdResult);
            var    itemToSend           = new AdventureLog
            {
                AdventureLogID = adventureLogId,
                UserId         = null,
                LogTitle       = "Session 23: I changed my mind",
                LogBody        = "<p><b>The dwarf punched the stupid elf.</b></p>"
            };
            var sentContent = JsonConvert.SerializeObject(itemToSend);

            // Act
            await client.PutAsync(url, new StringContent(sentContent, Encoding.UTF8, "application/json"));

            AdventureLog adventureLog = _queryHelper.SelectAdventureLogQuery(adventureLogId);

            // Assert
            Assert.Equal(itemToSend.LogTitle, adventureLog.LogTitle);
            Assert.Equal(itemToSend.LogBody, adventureLog.LogBody);
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> NewAdventureLog([FromQuery] int adventureLogID)
        {
            AdventureLog log = await _context.AdventureLogs.FindAsync(adventureLogID);

            return(View(log));
        }