Example #1
0
    private void ParseGameEffect_SpawnMinionThrow(TextFieldParser parser, EffectDef def)
    {
        Debug.Log("Hey are you parsing SpawnMinonThrow?");
        TagWeights tagWeights = Utils.ParseTagWeights(parser, "Params", true);

        if (tagWeights == null)
        {
            def.worldMethod = GameEffectManager.CreateMethod_LogMessage(LogLevel.Error, "Broken SpawnMinionThrow GameEffect for: " + def.id);
        }
        else
        {
            int    level;
            string tagAndWeight = tagWeights.GetTagAndWeight(0, out level);
            def.worldMethod = CreateMethod_SpawnMinionThrow(tagAndWeight, level, Utils.TryParseFloat(parser, "Radius", null), Utils.TryParseFloat(parser, "Duration", null));
        }
    }
Example #2
0
 private void ParseGameEffect_MaybeSpawnMinions(TextFieldParser parser, EffectDef def)
 {
     // 20% chance to spawn minions?
     if (UnityEngine.Random.Range(0, 100) < 5)
     {
         TagWeights tagWeights = Utils.ParseTagWeights(parser, "Params", true);
         if (tagWeights == null)
         {
             def.worldMethod = GameEffectManager.CreateMethod_LogMessage(LogLevel.Error, "Broken SpawnMinions GameEffect for: " + def.id);
         }
         else
         {
             string tagAndWeight = tagWeights.GetTagAndWeight(0, out int level);
             def.worldMethod = GameEffectManager.CreateMethod_SpawnMinions(tagAndWeight, level, Utils.TryParseFloat(parser, "Radius", null), Utils.TryParseFloat(parser, "Duration", null));
         }
     }
 }
Example #3
0
        public IActionResult Rate(String gameName, Int16 rating)
        {
            HttpContext.Session.Remove(list_key);
            try
            {
                using (var db = new WgsipContext())
                {
                    int weight = 0;
                    switch (rating)
                    {
                    case 1:
                        weight = -2;
                        break;

                    case 2:
                        weight = -1;
                        break;

                    case 3:
                        weight = 0;
                        break;

                    case 4:
                        weight = 1;
                        break;

                    case 5:
                        weight = 2;
                        break;
                    }
                    //get gameid
                    int gameid = db.Games.Where(g => g.GameName.ToLower().Equals(gameName.ToLower())).First().GameId;
                    //get publisherid
                    int publisherid = db.Games.Include(g => g.Publisher).Where(g => g.GameName.ToLower().Equals(gameName.ToLower())).First().Publisher.PublisherId;
                    //get genreid
                    int genreid = db.Games.Include(g => g.Genre).Where(g => g.GameName.ToLower().Equals(gameName.ToLower())).First().Genre.GenreId;

                    // create list of tags assosiated with this game
                    List <GameTag> tagsForGame = db.GameTags.Include(g => g.Game).Include(g => g.Tag)
                                                 .Where(g => g.Game.GameId == gameid).ToList();
                    var played_game = db.PlayedGames.Include(pg => pg.User).Include(pg => pg.Game)
                                      .First(pg =>
                                             pg.Game.GameName.ToLower().Equals(gameName.ToLower()) &&
                                             pg.User.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower())
                                             );

                    int prevWeight = 0;
                    switch (played_game.Rating)
                    {
                    case 1:
                        prevWeight = -2;
                        break;

                    case 2:
                        prevWeight = -1;
                        break;

                    case 3:
                        prevWeight = 0;
                        break;

                    case 4:
                        prevWeight = 1;
                        break;

                    case 5:
                        prevWeight = 2;
                        break;
                    }

                    played_game.Rating = rating;
                    // adjust weight of the publisher
                    try
                    {
                        var pub = db.PublisherWeights.Include(pg => pg.User).Include(pg => pg.Publisher)
                                  .First(pg =>
                                         pg.Publisher.PublisherId == publisherid &&
                                         pg.User.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower())
                                         );
                        pub.Weight += prevWeight * -1; //remove the change from the previous rating.
                        pub.Weight += weight;
                    }
                    catch (Exception)
                    {
                        PublisherWeights pW = new PublisherWeights();
                        pW.Publisher = db.Publishers.First(p => p.PublisherId == publisherid);
                        pW.User      = db.Accounts.First(a => a.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower()));
                        pW.Weight    = weight;
                        db.PublisherWeights.Add(pW);
                    }

                    //adjust weight for the genre
                    try
                    {
                        var gen = db.GenreWeights.Include(pg => pg.User).Include(pg => pg.Genre)
                                  .First(pg =>
                                         pg.Genre.GenreId == genreid &&
                                         pg.User.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower())
                                         );
                        gen.Weight += prevWeight * -1; //remove the change from the previous rating.
                        gen.Weight += weight;
                    }
                    catch (Exception)
                    {
                        GenreWeights gW = new GenreWeights();
                        gW.Genre  = db.Genres.First(g => g.GenreId == genreid);
                        gW.User   = db.Accounts.First(a => a.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower()));
                        gW.Weight = weight;
                        db.GenreWeights.Add(gW);
                    }

                    /*tag weight is assigned for each tag a game has the tag weight is assigned
                     * the weight dived by the number of tagsa game has*/
                    foreach (GameTag tag in tagsForGame)
                    {
                        //get the tagid
                        int tagid = tag.Tag.TagId;

                        //adjust weight for each tag
                        try
                        {
                            var t = db.TagWeights.Include(pg => pg.User).Include(pg => pg.Tag)
                                    .First(pg =>
                                           pg.Tag.TagId == tagid &&
                                           pg.User.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower())
                                           );
                            t.Weight += (prevWeight / tagsForGame.Count) * -1; //remove the change from the previous rating.
                            t.Weight += (weight / tagsForGame.Count);
                        }
                        catch (Exception)
                        {
                            TagWeights tW = new TagWeights();
                            tW.Tag    = db.Tags.First(t => t.TagId == tagid);
                            tW.User   = db.Accounts.First(a => a.AccountEmail.ToLower().Equals(User.Identity.Name.ToLower()));
                            tW.Weight = weight;
                            db.TagWeights.Add(tW);
                        }
                    }

                    db.SaveChanges();
                }
                return(Json(new { message = "success" }));
            }
            catch (Exception e)
            {
                return(Json(new { message = e.Message }));
            }
        }