Exemple #1
0
        public Enemy(Point point, char symbol, Container cont) : base(point, symbol, cont)
        {
            //MovesCountPerTurn = 2;
            //IsWounded = true;
            this.Symbol = symbol;

#if ASCII_BUILD
            color = ConsoleColor.Red;
#endif
            Alive = true;

            if (string.IsNullOrEmpty(Name) && symbol != EnemySymbols.CommonEnemySymbol)
            {
                Name = NameFromSymbol(symbol);
            }

            AddFightItem(FightItemKind.Stone);
            AddFightItem(FightItemKind.ThrowingKnife);
            AddFightItem(FightItemKind.ExplosiveCocktail);
            AddFightItem(FightItemKind.PoisonCocktail);
            //fightItems[FightItemKind.HunterTrap] = new ProjectileFightItem(FightItemKind.HunterTrap, this) { Count = RandHelper.GetRandomInt(3) + 1 };

            this.ActiveFightItem = RandHelper.GetRandomElem <FightItem>(this.fightItems.Values.ToList());

            SetResist(EntityStatKind.ResistCold, 15);
            SetResist(EntityStatKind.ResistFire, 15);
            SetResist(EntityStatKind.ResistPoison, 15);
            SetResist(EntityStatKind.ResistLighting, 15);

            Stats.SetNominal(EntityStatKind.MeleeAttack, BaseStrength.Value.Nominal + 2);//attack is same as str for a simple entity
        }
Exemple #2
0
        protected T GetRandom <T>(Dictionary <string, Func <string, T> > factory)
        {
            var index       = RandHelper.GetRandomInt(factory.Count);
            var lootCreator = factory.ElementAt(index);

            return(lootCreator.Value(lootCreator.Key));
        }
Exemple #3
0
        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="uploadFile">上传文件</param>
        /// <param name="pathDir">上传目录</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="fileType">验证格式(空为不限制)</param>
        /// <param name="fileSize">文件大小(单位KB,0为不限制)</param>
        /// <param name="response">响应内容</param>
        /// <returns></returns>
        public static FileModel UpLoad(HttpPostedFileBase uploadFile, String pathDir, String fileName, String[] fileType, long fileSize, ref String response)
        {
            if (!pathDir.EndsWith("/"))
            {
                pathDir = pathDir + "/";
            }
            if (!pathDir.StartsWith("/"))
            {
                pathDir = "/" + pathDir;
            }
            pathDir += DateTime.UtcNow.ToString("yyyyMM") + "/";
            var fileExtName = Path.GetExtension(uploadFile.FileName).ToLower();

            if (fileType != null && fileType.Length > 0)
            {
                if (!fileType.Any(a => a.ToLower() == fileExtName))
                {
                    response = "文件格式不正确!支持格式(" + String.Join("|", fileType) + ")";
                    return(null);
                }
            }
            if (fileName.IsNull())
            {
                fileName = RandHelper.GetTimeRandom("ddHHmmssffff");
            }
            string filePath = pathDir + fileName + fileExtName;

            return(UpLoad(uploadFile, filePath, fileSize, ref response));
        }
Exemple #4
0
        public Enemy(Point point, char symbol, Container cont) : base(point, symbol, cont)
        {
            //MovesCountPerTurn = 2;
            //IsWounded = true;
            this.Symbol = symbol;

#if ASCII_BUILD
            color = ConsoleColor.Red;
#endif
            Alive = true;

            if (string.IsNullOrEmpty(Name) && symbol != EnemySymbols.CommonEnemySymbol)
            {
                Name = NameFromSymbol(symbol);
            }

            AddFightItem(FightItemKind.Stone);
            var knife = AddFightItem(FightItemKind.ThrowingKnife);
            AddFightItem(FightItemKind.ExplosiveCocktail);
            AddFightItem(FightItemKind.PoisonCocktail);
            //var net = AddFightItem(FightItemKind.WeightedNet);
            //fightItems[FightItemKind.HunterTrap] = new ProjectileFightItem(FightItemKind.HunterTrap, this) { Count = RandHelper.GetRandomInt(3) + 1 };

            SetActiveFightItem(RandHelper.GetRandomElem <FightItem>(this.fightItems.Values.ToList()).FightItemKind);
            //SetActiveFightItem(knife.FightItemKind);

            SetResist(EntityStatKind.ResistCold, 15);
            SetResist(EntityStatKind.ResistFire, 15);
            SetResist(EntityStatKind.ResistPoison, 15);
            SetResist(EntityStatKind.ResistLighting, 15);
        }
        public override Loot GetRandom(int level)
        {
            var index       = RandHelper.GetRandomEnumValue <EquipmentKind>(new[] { EquipmentKind.God, EquipmentKind.Trophy, EquipmentKind.Unset });
            var lootCreator = lootCreators[index];

            return(lootCreator.GetRandom(level));
        }
        /**
         *
         * 查询订单
         * @param WxPayData inputObj 提交给查询订单API的参数
         * @param int timeOut 超时时间
         * @throws WxPayException
         * @return 成功时返回订单查询结果,其他抛异常
         */
        public static WxPayData OrderQuery(WxPayData inputObj, int timeOut = 6)
        {
            string url = "https://api.mch.weixin.qq.com/pay/orderquery";

            //检测必填参数
            if (!inputObj.IsSet("out_trade_no") && !inputObj.IsSet("transaction_id"))
            {
                throw new WxPayException("订单查询接口中,out_trade_no、transaction_id至少填一个!");
            }

            inputObj.SetValue("appid", WxPayConfig.APPID);                 //公众账号ID
            inputObj.SetValue("mch_id", WxPayConfig.MCHID);                //商户号
            inputObj.SetValue("nonce_str", RandHelper.GenerateNonceStr()); //随机字符串
            inputObj.SetValue("sign", inputObj.MakeSign());                //签名

            string xml = inputObj.ToXml();

            var start = DateTime.Now;

            var    requestResult = CoreHelper.GetHttpResult(url, xml, contentType: KeyModel.ContentType.Xml);
            string response      = requestResult.Obj; // HttpService.Post(xml, url, false, timeOut);


            var end      = DateTime.Now;
            int timeCost = (int)((end - start).TotalMilliseconds);//获得接口耗时

            //将xml格式的数据转化为对象以返回
            WxPayData result = new WxPayData();

            result.FromXml(response);

            return(result);
        }
Exemple #7
0
        protected virtual void CreateDynamicTiles(List <Dungeons.TileContainers.DungeonNode> mazeNodes)
        {
            if (mazeNodes.Any(i => !i.Created))
            {
                Logger.LogError("!i.Created ");
                return;
            }
            {
                var roomGen = CreateRoomContentGeneratorForExtraEnemies();
                foreach (var en in extraEnemies)
                {
                    var maze = mazeNodes.GetRandomElem();
                    roomGen.AddExtraEnemy(maze, en);
                }
            }

            if (LevelIndex < MaxLevelIndex)
            {
                var indexWithStairsDown = mazeNodes.Count - 1;
                if (RandHelper.GetRandomDouble() > .5f)
                {
                    indexWithStairsDown = mazeNodes.Count - 2;
                }

                if (indexWithStairsDown < 0)
                {
                    indexWithStairsDown = 0;
                }

                var maze = mazeNodes[indexWithStairsDown];

                GenerateStairsDown(maze);
                //node.SetTile(stairs, new System.Drawing.Point(3, 1));
            }
        }
Exemple #8
0
 public T RouteTo(List <T> instances)
 {
     if (instances?.Count > 0)
     {
         return(instances[RandHelper.Next(0, instances.Count)]);
     }
     return(default(T));
 }
Exemple #9
0
        protected Equipment GetRandomFromAll()
        {
            var index       = RandHelper.GetRandomInt(factory.Count);
            var lootCreator = factory.ElementAt(index);
            var loot        = lootCreator.Value(lootCreator.Key);

            return(loot);
        }
Exemple #10
0
 public ProjectileFightItem AddFightItem(FightItemKind kind)
 {
     fightItems[kind] = new ProjectileFightItem(kind, this)
     {
         Count = RandHelper.GetRandomInt(2) + 1
     };
     return(fightItems[kind] as ProjectileFightItem);
 }
Exemple #11
0
        private Cell ChooseNextCell(List <Cell> cells)
        {
            var randomDouble = RandHelper.GetRand().NextDouble();
            var nextCell     = randomDouble < Policy.epsilon ? ChooseRandom(cells) : ChooseHighestRewardValue(cells);

            Policy.UpdateEpsilon();
            return(nextCell);
        }
Exemple #12
0
        public override Loot GetRandom(int level)
        {
            var subFac = factories.Where(i => i != BooksFactory).ToList();

            var index       = RandHelper.GetRandomInt(subFac.Count);
            var lootCreator = subFac[index];

            return(lootCreator.GetRandom(level));
        }
Exemple #13
0
        /// <summary>
        /// 支付宝表单提交字符串
        /// </summary>
        public string FormHtml(out string tradeNo)
        {
            tradeNo = RandHelper.GenerateNonceStr();

            StringBuilder build = new StringBuilder();

            //把请求参数打包成数组
            SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();

            sParaTemp.Add("service", StringHelper.Get(this.ServiceName));                               //调用的接口名,无需修改
            sParaTemp.Add("partner", StringHelper.Get(this.PartnerNo));                                 // 合作身份者ID,签约账号,以2088开头由16位纯数字组成的字符串,查看地址:https://b.alipay.com/order/pidAndKey.htm
            sParaTemp.Add("seller_id", StringHelper.Get(this.SellerId));                                // 收款支付宝账号,以2088开头由16位纯数字组成的字符串,一般情况下收款账号就是签约账号
            sParaTemp.Add("_input_charset", StringHelper.Get(this.InputCharset));                       // 字符编码格式 目前支持 gbk 或 utf-8
            sParaTemp.Add("payment_type", "1");                                                         // 支付类型 ,无需修改
            sParaTemp.Add("notify_url", StringHelper.Get(this.NotifyUrl));                              // 服务器异步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
            sParaTemp.Add("return_url", StringHelper.Get(this.ReturnUrl));                              // 页面跳转同步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问

            #region 防调鱼配置

            ////↓↓↓↓↓↓↓↓↓↓请在这里配置防钓鱼信息,如果没开通防钓鱼功能,请忽视不要填写 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
            ////防钓鱼时间戳  若要使用请调用类文件submit中的Query_timestamp函数
            //public static string anti_phishing_key = "";
            ////客户端的IP地址 非局域网的外网IP地址,如:221.0.0.1
            //public static string exter_invoke_ip = "";
            ////↑↑↑↑↑↑↑↑↑↑请在这里配置防钓鱼信息,如果没开通防钓鱼功能,请忽视不要填写 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
            sParaTemp.Add("anti_phishing_key", "");
            sParaTemp.Add("exter_invoke_ip", "");

            #endregion

            sParaTemp.Add("out_trade_no", StringHelper.Get(tradeNo));
            sParaTemp.Add("subject", StringHelper.Get(this.Subject));                           //商品名称
            sParaTemp.Add("total_fee", StringHelper.Get(this.Money));
            sParaTemp.Add("body", StringHelper.Get(this.Body));
            sParaTemp.Add("extra_common_param", StringHelper.Get(this.ExtraCommonParam));


            //对参数进行过滤排序及生成字符串
            Dictionary <string, string> par = FilterPara(sParaTemp);
            string prestr = CreateLinkString(par);

            par.Add("sign", AlipayMd5Sign(prestr, StringHelper.Get(this.Key), StringHelper.Get(this.InputCharset)));
            par.Add("sign_type", "MD5"); // 签名方式


            //构造请求信息
            build.Append("<form id='alipaysubmit' name='alipaysubmit' action='" + StringHelper.Get(this.Gateway) + "_input_charset=" + StringHelper.Get(this.InputCharset) + "' method='GET'>");
            foreach (KeyValuePair <string, string> temp in par)
            {
                build.Append("<input type='hidden' name='" + temp.Key + "' value='" + temp.Value + "'/>");
            }
            build.Append("<input type='submit' value='确认' style='display:none;'></form>");
            build.Append("<script>document.forms['alipaysubmit'].submit();</script>");

            //submit按钮控件请不要含有name属性
            return(build.ToString());
        }
        public static T[] GetRandInstanceArr(int len1, int arrayLen)
        {
            RandHelper helper = new RandHelper();

            T[] res = new T[arrayLen];
            for (int f = 0; f < arrayLen; f++)
            {
                res[f] = new T().GetRandInstance(helper, len1);
            }
            return(res);
        }
Exemple #15
0
        public int m_finishFrame  = 0; //目标帧

        public BattleLogicManager(BattleData battleData, int _seed)
        {
            m_BattleData       = battleData;
            m_TroopLogicCtrl   = new TroopLogicCtrl(this);
            m_Rand             = new RandHelper(_seed);
            m_BattleData.mSeed = m_Rand.GetSeed();
            SetCurrentFrame(1);
            m_finishFrame  = 0;
            m_logicAddTime = 0f;
            m_isFinish     = false;
        }
Exemple #16
0
        public static float GetRandAttackVariation(float currentAttackValue, List <int> attackValueDecrease, bool signed)
        {
            var percentToDecrease = RandHelper.GetRandomElem(attackValueDecrease);
            var variation         = CalcPercentageValue(currentAttackValue, percentToDecrease);

            var sign = 1;

            if (signed)
            {
                sign = RandHelper.Random.NextDouble() > .5f ? -1 : 1;
            }

            return(sign * variation);
        }
Exemple #17
0
        /**
         * 生成扫描支付模式一URL
         * @param productId 商品ID
         * @return 模式一URL
         */
        public static string GetPrePayUrl(string productId)
        {
            WxPayData data = new WxPayData();

            data.SetValue("appid", WxPayConfig.APPID);                 //公众帐号id
            data.SetValue("mch_id", WxPayConfig.MCHID);                //商户号
            data.SetValue("time_stamp", GenerateTimeStamp());          //时间戳
            data.SetValue("nonce_str", RandHelper.GenerateNonceStr()); //随机字符串
            data.SetValue("product_id", productId);                    //商品ID
            data.SetValue("sign", data.MakeSign());                    //签名
            string str = ToUrlParams(data.GetValues());                //转换为URL串
            string url = "weixin://wxpay/bizpayurl?" + str;

            return(url);
        }
Exemple #18
0
        public T RollDice(T unset, T[] skip, double factor = 0)
        {
            var rand = RandHelper.GetRandomDouble();

            if (factor != 0)
            {
                rand -= factor;
            }
            var matches = GetMatchesAboveThreashold(rand);

            if (matches.Any())
            {
                return(RandHelper.GetRandomElem <T>(matches, skip));
            }
            return(unset);
        }
 protected void MakeMagic(EquipmentClass eqClass, Equipment eq)
 {
     if (eq.Class == EquipmentClass.Unique)
     {
         return;
     }
     if (eq.IsPlain())
     {
         eq.MakeMagic();
     }
     if (!eq.IsSecondMagicLevel && eqClass == EquipmentClass.MagicSecLevel)
     {
         var stats = eq.GetPossibleMagicStats();
         var stat  = RandHelper.GetRandomElem(stats);
         eq.MakeMagicSecLevel(stat.Key, 3);//TODO !
     }
 }
Exemple #20
0
        internal override bool CanMakeRandomMove()
        {
            if (PreventMove)
            {
                return(false);
            }
            if (RandMoveCoolDown > 0)
            {
                RandMoveCoolDown--;
            }
            var res = RandMoveCoolDown == 0;

            if (res)
            {
                RandMoveCoolDown = RandHelper.GetRandomInt(4);
            }
            return(res);
        }
Exemple #21
0
        protected Tuple <string, EquipmentMaterial> GetRandomFromList(int level, ref EquipmentMaterial mat, List <Equipment> plains)
        {
            Tuple <string, EquipmentMaterial> res = null;
            var eqsAtLevel = plains.Where(i => i.LevelIndex == level).ToList();

            var eq = RandHelper.GetRandomElem <Equipment>(eqsAtLevel);

            if (eq != null)
            {
                if (eq.IsMaterialAware() && mat == EquipmentMaterial.Unset)
                {
                    mat = EquipmentMaterial.Bronze;
                }
                res = new Tuple <string, EquipmentMaterial>(eq.tag1, mat);
            }

            return(res);
        }
Exemple #22
0
        /**
         * 生成直接支付url,支付url有效期为2小时,模式二
         * @param productId 商品ID
         * @return 模式二URL
         */
        public static string GetPayUrl(string rechargeRecordId, string tags, string descript, decimal moneyValue, out string tradeNo)
        {
            tradeNo = RandHelper.GenerateNonceStr();
            WxPayData data = new WxPayData();

            data.SetValue("body", descript);                                                      //商品描述
            data.SetValue("attach", "");                                                          //附加数据
            data.SetValue("out_trade_no", tradeNo);                                               //随机字符串
            data.SetValue("total_fee", StringHelper.Get(IntHelper.Get(moneyValue * 100)));        //总金额
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));                 //交易起始时间
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss")); //交易结束时间
            data.SetValue("goods_tag", tags);                                                     //商品标记
            data.SetValue("trade_type", "NATIVE");                                                //交易类型
            data.SetValue("product_id", rechargeRecordId);                                        //商品ID
            WxPayData result = UnifiedOrder(data);                                                //调用统一下单接口
            string    url    = result.GetValue("code_url").ToString();                            //获得统一下单接口返回的二维码链接

            return(url);
        }
        private EntranceSide CalcSide(EntranceSide current, EntranceSide next, float chanceForLevelTurn)//, int currentNodeIndex)
        {
            if (info != null && info.ForcedNextRoomSide != null)
            {
                return(info.ForcedNextRoomSide.Value);
            }

            EntranceSide side = GetRandSide();

            if (current == next)
            {
                if (RandHelper.GetRandomDouble() >= chanceForLevelTurn)
                {
                    side = side == EntranceSide.Bottom ? EntranceSide.Right : EntranceSide.Bottom;
                }
            }

            return(side);
        }
Exemple #24
0
        private static ProjectileFightItem CreateFightItem(FightItemKind fik)
        {
            int max = 3;
            int add = 3;
            var fi  = new ProjectileFightItem(fik, null)
            {
            };

            if (fik == FightItemKind.PlainArrow || fik == FightItemKind.PlainBolt)
            {
                max = 6;
            }
            if (fik == FightItemKind.HunterTrap)
            {
                max = 1;
                add = 2;
            }

            fi.Count = RandHelper.GetRandomInt(max) + add;
            return(fi);
        }
        Interior?GenerateRandomSimpleInterior(bool addFinishingDecorations = false)
        {
            Interior?interior = null;

            if (Width - generationInfo.MinSimpleInteriorSize > 4 &&
                Height - generationInfo.MinSimpleInteriorSize > 4)
            {
                interior = RandHelper.GetRandomEnumValue <Interior>();
                GenerateInterior(interior.Value);
            }
            else
            {
                addFinishingDecorations = true;
            }
            if (addFinishingDecorations)
            {
                AddDecorations();
            }

            return(interior);
        }
Exemple #26
0
        public void SetRandomKindAndLevelSize(int gameLevel, bool setKind)
        {
            GameLevel = gameLevel;

            if (setKind)
            {
                GemKind = RandHelper.GetRandomEnumValue <GemKind>();
            }
            EnchanterSize = EnchanterSize.Small;
            var smaller = RandHelper.GetRandomDouble() < 0.5f;

            if (gameLevel >= 10)
            {
                EnchanterSize = EnchanterSize.Big;
            }
            else if (gameLevel >= 8)
            {
                EnchanterSize = smaller ? EnchanterSize.Medium : EnchanterSize.Big;
            }
            else if (gameLevel >= 6)
            {
                EnchanterSize = smaller ? EnchanterSize.Small : EnchanterSize.Medium;
            }
            else if (gameLevel >= 4)
            {
                smaller = false;
            }

            if (!smaller && gameLevel < 10)
            {
                Damaged = true;
            }

            if (RandHelper.GetRandomDouble() < 0.3f)
            {
                Damaged = true;
            }

            SetProps();
        }
Exemple #27
0
        protected virtual Tuple <string, EquipmentMaterial> GetLootAtLevel(int level)
        {
            Tuple <string, EquipmentMaterial> res = new Tuple <string, EquipmentMaterial>("", EquipmentMaterial.Unset);
            EquipmentMaterial mat = EquipmentMaterial.Unset;
            bool upgMaterial      = false;

            if (level > MaterialProps.SteelDropLootSrcLevel)
            {
                mat = EquipmentMaterial.Iron;
                if (RandHelper.GetRandomDouble() > 0.33f)//make it more unpredictable
                {
                    mat         = EquipmentMaterial.Steel;
                    upgMaterial = true;
                }
            }
            else if (level > MaterialProps.IronDropLootSrcLevel)
            {
                if (RandHelper.GetRandomDouble() > 0.33f)
                {
                    mat         = EquipmentMaterial.Iron;
                    upgMaterial = true;
                }
            }

            if (upgMaterial)
            {
                level--;
            }

            var plains = prototypes.Values.Where(i => i.Class == EquipmentClass.Plain).ToList();

            res = GetRandomFromList(level, ref mat, plains);
            //if (eq !=null mat != EquipmentMaterial.Bronze)
            //{
            //  EnsureMaterialFromLootSource(eq);
            //}
            return(res);
        }
        public void GenerateRandomInterior(EventHandler <DungeonNode> CustomInteriorDecorator)
        {
            if (!Inited())
            {
                return;
            }

            if (!generationInfo.GenerateRandomInterior && !generationInfo.ForceChildIslandInterior)
            {
                return;
            }

            Interior?interior = null;
            var      rand     = RandHelper.GetRandomDouble();

            if (!dungeonNode.Secret && generationInfo.ChildIslandAllowed && (generationInfo.ForceChildIslandInterior || rand < .33))
            {
                var island = GenerateChildIslands();
                if (island == null)
                {
                    interior = GenerateRandomSimpleInterior(true);
                }
                else if (CustomInteriorDecorator != null)
                {
                    CustomInteriorDecorator(this, island.FirstOrDefault());//currently only one is send
                }
            }
            else if (generationInfo.GenerateRandomInterior)
            {
                interior = GenerateRandomSimpleInterior();
            }

            if (generationInfo.GenerateRandomInterior)
            {
                GenerateRandomStonesBlocks();
            }
        }
Exemple #29
0
        private CraftingResult CraftOneEq(Equipment srcEq)
        {
            if (srcEq.WasCraftedBy(RecipeKind.TwoEq))
            {
                return(ReturnCraftingError("Can not craft equipment which was already crafted in pairs"));
            }
            ;

            var srcLootKind   = srcEq.EquipmentKind;
            var lks           = Equipment.GetPossibleLootKindsForCrafting().ToList();
            var destLk        = RandHelper.GetRandomElem <EquipmentKind>(lks, new EquipmentKind[] { srcLootKind });
            var lootGenerator = container.GetInstance <LootGenerator>();
            var destEq        = lootGenerator.GetRandomEquipment(destLk, srcEq.MinDropDungeonLevel, null);

            if (srcEq.Class == EquipmentClass.Magic)
            {
                destEq.SetClass(EquipmentClass.Magic, srcEq.MinDropDungeonLevel, null, srcEq.IsSecondMagicLevel);
            }
            var srcStatsCount = srcEq.GetMagicStats().Count;

            if (srcStatsCount > destEq.GetMagicStats().Count)
            {
                var diff = srcStatsCount - destEq.GetMagicStats().Count;
                for (int i = 0; i < diff; i++)
                {
                    destEq.AddRandomMagicStat();
                }
            }
            if (srcEq.Enchantable)
            {
                destEq.MakeEnchantable();
            }
            destEq.WasCrafted     = true;
            destEq.CraftingRecipe = RecipeKind.OneEq;
            return(ReturnCraftedLoot(destEq));
        }
Exemple #30
0
 public Plant() : this(RandHelper.GetRandomEnumValue <PlantKind>(true))
 {
 }