} // end Minus public void Plus(IRealData data) { if (null == data || false == IsLive || HP == XHP && MP == XMP) { return; } // end if HP = HP + data.HP; MP = MP + data.MP; if (data.HPR > 0) { HP = HP + MathTool.Percent(XHP - HP, data.HPR); } // end if if (data.MPR > 0) { MP = MP + MathTool.Percent(XMP - MP, data.MPR); } // end if if (data.XHR > 0) { HP = HP + MathTool.Percent(XHP, data.XHR); } // end if if (data.XMR > 0) { MP = MP + MathTool.Percent(XMP, data.XMR); } // end if HP = MathTool.Clamp(HP, 0, XHP); MP = MathTool.Clamp(MP, 0, XMP); } // end Plus
public override void Init(int width, int height) { base.Init(width, height); worldMap = PicLoader.Read("Map", "worldmap.JPG"); Graphics g = Graphics.FromImage(worldMap); foreach (var sceneConfig in ConfigData.SceneDict.Values) { if (sceneConfig.Icon == "") { continue; } Image image = PicLoader.Read("MapIcon", string.Format("{0}.PNG", sceneConfig.Icon)); iconSizeDict[sceneConfig.Id] = new Size(image.Width, image.Height); Rectangle destRect = new Rectangle(sceneConfig.IconX, sceneConfig.IconY, image.Width, image.Height); g.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, sceneConfig.Level > UserProfile.InfoBasic.Level ? HSImageAttributes.ToRed : HSImageAttributes.ToGray); image.Dispose(); if (sceneConfig.Id == UserProfile.InfoBasic.MapId) { baseX = sceneConfig.IconX - 750 / 2 + 30; baseY = sceneConfig.IconY - 500 / 2 + 30; baseX = MathTool.Clamp(baseX, 0, worldMap.Width - 750); baseY = MathTool.Clamp(baseY, 0, worldMap.Height - 500); } } g.Dispose(); showImage = true; }
} // end Plus public void Plus(IEquipInfo info) { if (null == info) { return; } // end if XHP = XHP + info.attributeInfo.XHP; XMP = XMP + info.attributeInfo.XMP; NATK = NATK + info.attributeInfo.NATK; XATK = XATK + info.attributeInfo.XATK; NMGK = NMGK + info.attributeInfo.NMGK; XMGK = XMGK + info.attributeInfo.XMGK; HOT = HOT + info.attributeInfo.HOT; MOT = MOT + info.attributeInfo.MOT; DEF = DEF + info.attributeInfo.DEF; RGS = RGS + info.attributeInfo.RGS; if (info.attributeInfo.ASP != 0) { ASP = MathTool.Clamp(ASP * (info.attributeInfo.ASP + 100f) / 100f, 0.2f, 2f); } if (info.attributeInfo.MSP != 0) { MSP = MathTool.Clamp(MSP * (info.attributeInfo.MSP + 100f) / 100f, 0.2f, 5f); } HIT = MathTool.Clamp(HIT + info.attributeInfo.HIT, 0, 100); AVD = MathTool.Clamp(AVD + info.attributeInfo.AVD, 0, 60); CRT = MathTool.Clamp(CRT + info.attributeInfo.CRT, 0, 100); } // end Plus
public override void Init(int width, int height) { base.Init(width, height); tileManager.Init(); baseX = MathTool.Clamp(baseX, 0, tileManager.MapPixelWidth - doubleBuffedPanel1.Width); baseY = MathTool.Clamp(baseY, 0, tileManager.MapPixelHeight - doubleBuffedPanel1.Height); //test code battleManager.AddUnit(new HeroSam(43020101, 15, 15, 1)); battleManager.AddUnit(new HeroSam(43020102, 15, 13, 1)); battleManager.AddUnit(new MonsterSam(43000005, 18, 18, 4)); battleManager.AddUnit(new MonsterSam(43000005, 18, 21, 4)); showImage = true; isPlayerRound = true; }
/// <summary> /// Interpolates between two orientations using spherical linear interpolation. /// </summary> /// <param name="from">Quaternion that represents the starting orientation.</param> /// <param name="to">Quaternion that represents the ending orientation</param> /// <param name="t">Interpolation coefficient.</param> /// <param name="useShortestPath">Boolean that indicates whether to compute quaternions that constitute the shortest possible arc on a four-dimensional unit sphere.</param> /// <returns>Quaternion that represents the orientation resulting from the interpolation.</returns> public static Quaternion Slerp(Quaternion from, Quaternion to, double t, bool useShortestPath) { double cosTheta = MathTool.Clamp(from.X * to.X + from.Y * to.Y + from.Z * to.Z + from.W * to.W, -1.0, 1.0); if (useShortestPath && cosTheta < 0) { from = new Quaternion(-from.X, -from.Y, -from.Z, -from.W); cosTheta = -cosTheta; } double theta = Math.Acos(cosTheta); double sinTheta = Math.Sin(theta); double t0 = sinTheta > 0.001 ? Math.Sin((1.0f - t) * theta) / sinTheta : 1.0f - t; double t1 = sinTheta > 0.001 ? Math.Sin(t * theta) / sinTheta : t; return(new Quaternion(from.X * t0 + to.X * t1, from.Y * t0 + to.Y * t1, from.Z * t0 + to.Z * t1, from.W * t0 + to.W * t1)); }
private void WorldMapViewForm_MouseMove(object sender, MouseEventArgs e) { int truex = e.X - 15; int truey = e.Y - 35; string newSel = ""; foreach (var mapIconConfig in ConfigData.SceneDict.Values) { if (mapIconConfig.Icon == "") { continue; } var iconSize = iconSizeDict[mapIconConfig.Id]; if (truex > mapIconConfig.IconX - baseX && truey > mapIconConfig.IconY - baseY && truex < mapIconConfig.IconX - baseX + iconSize.Width && truey < mapIconConfig.IconY - baseY + iconSize.Height) { newSel = mapIconConfig.Icon; } } if (newSel != selectName) { selectName = newSel; Invalidate(); } if (mouseHold) { if (MathTool.GetDistance(e.Location, dragStartPos) > 3) { baseX -= e.Location.X - dragStartPos.X; baseY -= e.Location.Y - dragStartPos.Y; baseX = MathTool.Clamp(baseX, 0, worldMap.Width - 750); baseY = MathTool.Clamp(baseY, 0, worldMap.Height - 500); dragStartPos = e.Location; Invalidate(); } dragStartPos = e.Location; } else { dragStartPos = e.Location; } }
public static void TestClamp() { Assert.AreEqual(100, MathTool.Clamp <byte>(100, 0, 101)); Assert.AreEqual(200, MathTool.Clamp(500, 0, 200)); Assert.AreEqual(-10.2f, MathTool.Clamp(-20f, -10.2f, 0f)); Assert.IsTrue(MathTool.Clamp(true, false, true)); return; }
public void ChangeMap(int mapid, bool isWarp) { if (backPicture != null) { backPicture.Dispose(); } SceneConfig sceneConfig = ConfigData.GetSceneConfig(mapid); backPicture = PicLoader.Read("Scene", string.Format("{0}.JPG", sceneConfig.Url)); sceneName = sceneConfig.Name; GenerateMiniMap(mapid, MathTool.Clamp(sceneConfig.IconX - 110, 0, 1688 - 300), MathTool.Clamp(sceneConfig.IconY - 110, 0, 1121 - 300)); UserProfile.InfoBasic.MapId = mapid; UserProfile.Profile.OnSwitchScene(); BlessManager.OnChangeMap(); OnBlessChange(); BlessManager.Update = OnBlessChange; SystemMenuManager.ResetIconState(); //reset main icon state todo remove check if (sceneConfig.Type == SceneTypes.Dungeon) { Rule = new SceneRuleDungeon(); } else if (sceneConfig.Type == SceneTypes.Town) { Rule = new SceneRuleTown(); } else { Rule = new SceneRuleCommon(); } TimeMinutes = (int)DateTime.Now.TimeOfDay.TotalMinutes; Rule.Init(mapid, TimeMinutes); sceneItems = SceneManager.RefreshSceneObjects(UserProfile.InfoBasic.MapId, width, height - 35, isWarp ? SceneManager.SceneFreshReason.Warp : SceneManager.SceneFreshReason.Load); if (UserProfile.InfoBasic.Position == 0 && sceneItems.Count > 0)//兜底处理 { UserProfile.InfoBasic.Position = sceneItems[0].Id; } parent.Invalidate(); }
} // end LoadNextLevel IEnumerator Start() { progressSlider = GameObject.Find("Canvas/ProgressSlider").GetComponent<Slider>(); progressText = progressSlider.transform.Find("Handle Slide Area/Handle/ProgressText").GetComponent<Text>(); AsyncOperation asyn = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName); asyn.allowSceneActivation = false; float smooth = 0; float progress = 0; WaitForEndOfFrame wait = new WaitForEndOfFrame(); while (smooth < 1) { if(progress < 1) progress = 1.125f * asyn.progress; // end if if (smooth < progress) smooth += Time.deltaTime; // end if progressText.text = (int)MathTool.Clamp((smooth * 100), 0, 100) + "%"; progressSlider.value = smooth; yield return wait; } // end while isLoaded = false; asyn.allowSceneActivation = true; } // end Start
/// <summary> /// Generates a new <see cref="ColorBlock" /> based on <paramref name="originalColorBlock" /> settings and <paramref name="newColor" />. /// </summary> /// <param name="originalColorBlock">A base <see cref="ColorBlock" /> instance.</param> /// <param name="newColor">A color to be applied to the new <see cref="ColorBlock" />.</param> /// <returns>The same <see cref="ColorBlock" /> but with different colors.</returns> public static ColorBlock GenerateColorBlock(this ColorBlock originalColorBlock, Color32 newColor) { ColorBlock colorBlock = new ColorBlock { normalColor = newColor, highlightedColor = new Color32((byte)(MathTool.Clamp((newColor.r + 10), byte.MinValue, byte.MaxValue)), (byte)(MathTool.Clamp((newColor.g + 20), byte.MinValue, byte.MaxValue)), (byte)(MathTool.Clamp((newColor.b + 10), byte.MinValue, byte.MaxValue)), byte.MaxValue), pressedColor = new Color32((byte)(MathTool.Clamp((newColor.r - 30), byte.MinValue, byte.MaxValue)), (byte)(MathTool.Clamp((newColor.g - 30), byte.MinValue, byte.MaxValue)), (byte)(MathTool.Clamp((newColor.b - 30), byte.MinValue, byte.MaxValue)), byte.MaxValue), selectedColor = newColor, disabledColor = new Color32((byte)(MathTool.Clamp((newColor.r * 0.6f), byte.MinValue, byte.MaxValue)), (byte)(MathTool.Clamp((newColor.g * 0.6f), byte.MinValue, byte.MaxValue)), (byte)(MathTool.Clamp((newColor.b * 0.6f), byte.MinValue, byte.MaxValue)), byte.MaxValue), colorMultiplier = originalColorBlock.colorMultiplier, fadeDuration = originalColorBlock.fadeDuration }; return(colorBlock); }
private void BattleForm_MouseMove(object sender, MouseEventArgs e) { if (mouseHold) { if (MathTool.GetDistance(e.Location, dragStartPos) > 3) { baseX -= e.Location.X - dragStartPos.X; baseY -= e.Location.Y - dragStartPos.Y; baseX = MathTool.Clamp(baseX, 0, tileManager.MapPixelWidth - doubleBuffedPanel1.Width); baseY = MathTool.Clamp(baseY, 0, tileManager.MapPixelHeight - doubleBuffedPanel1.Height); dragStartPos = e.Location; refreshAll.Fire(); } } else { dragStartPos = e.Location; var newTarget = battleManager.GetRegionUnitId(baseX + e.Location.X, baseY + e.Location.Y); if (newTarget != mouseOnId) { mouseOnId = newTarget; refreshAll.Fire(); } var newCellPos = new Point((dragStartPos.X + baseX) / TileManager.CellSize, (dragStartPos.Y + baseY) / TileManager.CellSize); if (newCellPos.X != selectCellPos.X || newCellPos.Y != selectCellPos.Y) { selectCellPos = newCellPos; refreshAll.Fire(); } if (battleMenu.OnMove(e.X, e.Y)) { refreshAll.Fire(); } } }
} // end Revive public void Init(IAttributeInfo initAttribute) { if (null == initAttribute) { return; } // end if XHP = initAttribute.XHP; XMP = initAttribute.XMP; NATK = initAttribute.NATK; XATK = initAttribute.XATK; NMGK = initAttribute.NMGK; XMGK = initAttribute.XMGK; HOT = initAttribute.HOT; MOT = initAttribute.MOT; DEF = initAttribute.DEF; RGS = initAttribute.RGS; ASP = initAttribute.ASP; MSP = initAttribute.MSP; HIT = MathTool.Clamp(initAttribute.HIT, 0, 100); AVD = MathTool.Clamp(initAttribute.AVD, 0, 60); CRT = MathTool.Clamp(initAttribute.CRT, 0, 100); } // end Init
private static void Tick() { DateTime now = DateTime.Now; List <UIElement> done = null; #region appearances foreach (TransitionState transitionState in activeAppearances.Values) { double p = MathTool.Clamp((now - transitionState.StartTime).TotalSeconds / (transitionState.EndTime - transitionState.StartTime).TotalSeconds, 0.0, 1.0); if (p == 1.0) { done = done ?? new List <UIElement>(); done.Add(transitionState.UIElement); transitionState.Progress = double.NaN; if (transitionState.Done != null) { transitionState.Done(transitionState.UIElement); } } else { transitionState.Progress = p; } } if (done != null) { foreach (UIElement uiElement in done) { activeAppearances.Remove(uiElement); } done.Clear(); } #endregion #region disappearances foreach (TransitionState transitionState in activeDisappearances.Values) { double p = MathTool.Clamp((now - transitionState.StartTime).TotalSeconds / (transitionState.EndTime - transitionState.StartTime).TotalSeconds, 0.0, 1.0); if (p == 1.0) { done = done ?? new List <UIElement>(); done.Add(transitionState.UIElement); transitionState.Progress = double.NaN; if (transitionState.Done != null) { transitionState.Done(transitionState.UIElement); } } else { transitionState.Progress = 1.0 - p; } } if (done != null) { foreach (UIElement uiElement in done) { activeDisappearances.Remove(uiElement); } } #endregion }
private void DoTrade() { int multi = int.Parse(evt.ParamList[0]); string type = "all"; if (evt.ParamList.Count >= 2) { type = evt.ParamList[1]; } double multiNeed = multi * MathTool.Clamp(1, 0.2f, 5); double multiGet = multi * MathTool.Clamp(1, 0.2f, 5); int index = 1; if (config.TradeGold > 0 && (type == "all" || type == "gold")) { var goldGet = GameResourceBook.InGoldSceneQuest(level, (int)(config.TradeGold * multiGet), true); if (goldGet > 0) { UserProfile.Profile.InfoBag.AddResource(GameResourceType.Gold, goldGet); var pictureRegion = ComplexRegion.GetResShowRegion(index, new Point(pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25), 60, ImageRegionCellType.Gold, (int)goldGet); vRegion.AddRegion(pictureRegion); index++; } } else if (config.TradeGold < 0) { var goldLoss = GameResourceBook.OutGoldSceneQuest(level, (int)(-config.TradeGold * multiNeed), true); if (goldLoss > 0) { UserProfile.Profile.InfoBag.SubResource(GameResourceType.Gold, goldLoss); var pictureRegion = ComplexRegion.GetResShowRegion(index, new Point(pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25), 60, ImageRegionCellType.Gold, (int)-goldLoss); vRegion.AddRegion(pictureRegion); index++; } } if (config.TradeFood > 0 && (type == "all" || type == "food")) { var foodGet = Math.Min(100, GameResourceBook.InFoodSceneQuest((int)(config.TradeFood * multiGet), true)); if (foodGet > 0) { UserProfile.Profile.InfoBasic.AddFood(foodGet); var pictureRegion = ComplexRegion.GetResShowRegion(index, new Point(pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25), 60, ImageRegionCellType.Food, (int)foodGet); vRegion.AddRegion(pictureRegion); index++; } } else if (config.TradeFood < 0) { var foodLoss = Math.Min(100, GameResourceBook.OutFoodSceneQuest((int)(-config.TradeFood * multiNeed), true)); if (foodLoss > 0) { UserProfile.Profile.InfoBasic.SubFood(foodLoss); var pictureRegion = ComplexRegion.GetResShowRegion(index, new Point(pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25), 60, ImageRegionCellType.Food, (int)-foodLoss); vRegion.AddRegion(pictureRegion); index++; } } if (config.TradeHealth > 0 && (type == "all" || type == "health")) { var healthGet = Math.Min(100, GameResourceBook.InHealthSceneQuest((int)(config.TradeHealth * multiGet), true)); if (healthGet > 0) { UserProfile.Profile.InfoBasic.AddHealth(healthGet); var pictureRegion = ComplexRegion.GetResShowRegion(index, new Point(pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25), 60, ImageRegionCellType.Health, (int)healthGet); vRegion.AddRegion(pictureRegion); index++; } } else if (config.TradeHealth < 0) { var healthLoss = Math.Min(100, GameResourceBook.OutHealthSceneQuest((int)(-config.TradeHealth * multiNeed), true)); if (healthLoss > 0) { UserProfile.Profile.InfoBasic.SubHealth(healthLoss); var pictureRegion = ComplexRegion.GetResShowRegion(index, new Point(pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25), 60, ImageRegionCellType.Health, (int)-healthLoss); vRegion.AddRegion(pictureRegion); index++; } } if (config.TradeMental > 0 && (type == "all" || type == "mental")) { var mentalGet = Math.Min(100, GameResourceBook.InMentalSceneQuest((int)(config.TradeMental * multiGet), true)); if (mentalGet > 0) { UserProfile.Profile.InfoBasic.AddMental(mentalGet); var pictureRegion = ComplexRegion.GetResShowRegion(index, new Point(pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25), 60, ImageRegionCellType.Mental, (int)mentalGet); vRegion.AddRegion(pictureRegion); index++; } } else if (config.TradeMental < 0) { var mentalLoss = Math.Min(100, GameResourceBook.OutMentalSceneQuest((int)(-config.TradeMental * multiNeed), true)); if (mentalLoss > 0) { UserProfile.Profile.InfoBasic.SubMental(mentalLoss); var pictureRegion = ComplexRegion.GetResShowRegion(index, new Point(pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25), 60, ImageRegionCellType.Mental, (int)-mentalLoss); vRegion.AddRegion(pictureRegion); index++; } } if (!string.IsNullOrEmpty(config.TradeDropItem)) { var itemList = DropBook.GetDropItemList(config.TradeDropItem); foreach (var itemId in itemList) { UserProfile.InfoBag.AddItem(itemId, 1); vRegion.AddRegion(new PictureRegion(index, pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25, 60, 60, PictureRegionCellType.Item, itemId)); index++; } } }
private int GetFinalMark(int mark) { return(MathTool.Clamp(mark * (10 + hardness) / 10, 1, 1000)); }
private void CheckCondition(string info) { string[] parms = info.Split('-'); var config = ConfigData.GetSceneQuestConfig(eventId); if (parms[0] == "cantrade") { int multi = int.Parse(parms[1]); string type = "all"; if (parms.Length > 2) { type = parms[2]; } double multiNeed = multi * MathTool.Clamp(1, 0.2, 5); double multiGet = multi * MathTool.Clamp(1, 0.2, 5); uint goldNeed = 0; if (config.TradeGold < 0) { goldNeed = GameResourceBook.OutGoldSceneQuest(level, (int)(-config.TradeGold * multiNeed), true); } uint foodNeed = 0; if (config.TradeFood < 0) { foodNeed = Math.Min(100, GameResourceBook.OutFoodSceneQuest((int)(-config.TradeFood * multiNeed), true)); } uint healthNeed = 0; if (config.TradeHealth < 0) { healthNeed = Math.Min(100, GameResourceBook.OutHealthSceneQuest((int)(-config.TradeHealth * multiNeed), true)); } uint mentalNeed = 0; if (config.TradeMental < 0) { mentalNeed = Math.Min(100, GameResourceBook.OutMentalSceneQuest((int)(-config.TradeMental * multiNeed), true)); } Disabled = !UserProfile.Profile.InfoBag.HasResource(GameResourceType.Gold, goldNeed) || UserProfile.Profile.InfoBasic.FoodPoint < foodNeed || UserProfile.Profile.InfoBasic.HealthPoint < healthNeed || UserProfile.Profile.InfoBasic.MentalPoint < mentalNeed; if (string.IsNullOrEmpty(config.TradeDropItem)) { uint goldAdd = 0; if (config.TradeGold > 0 && (type == "all" || type == "gold")) { goldAdd = GameResourceBook.InGoldSceneQuest(level, (int)(config.TradeGold * multiGet), true); } uint foodAdd = 0; if (config.TradeFood > 0 && (type == "all" || type == "food")) { foodAdd = Math.Min(100, GameResourceBook.InFoodSceneQuest((int)(config.TradeFood * multiGet), true)); } uint healthAdd = 0; if (config.TradeHealth > 0 && (type == "all" || type == "health")) { healthAdd = Math.Min(100, GameResourceBook.InHealthSceneQuest((int)(config.TradeHealth * multiGet), true)); } uint mentalAdd = 0; if (config.TradeMental > 0 && (type == "all" || type == "mental")) { mentalAdd = Math.Min(100, GameResourceBook.InMentalSceneQuest((int)(config.TradeMental * multiGet), true)); } Script = string.Format("获得{0}(消耗{1})", GetTradeStr(goldAdd, foodAdd, healthAdd, mentalAdd), GetTradeStr(goldNeed, foodNeed, healthNeed, mentalNeed)); } else { var dropId = DropBook.GetDropId(config.TradeDropItem); Script = string.Format("获得{0}(消耗{1})", ConfigData.GetDropConfig(dropId).Name, GetTradeStr(goldNeed, foodNeed, healthNeed, mentalNeed)); } } else if (parms[0] == "cantest") { int type = int.Parse(parms[1]); bool canConvert = type == 1; //是否允许转换成幸运检测 var testType = type == 1 ? config.TestType1 : config.TestType2; int sourceVal = UserProfile.InfoDungeon.GetAttrByStr(testType); Disabled = UserProfile.InfoDungeon.DungeonId <= 0 || sourceVal < 0; if (Disabled && canConvert) { Disabled = false; } if (!Disabled) { var biasData = type == 1 ? config.TestBias1 : config.TestBias2; if (UserProfile.InfoDungeon.DungeonId > 0 && UserProfile.InfoDungeon.GetAttrByStr(testType) >= 0) { var attrNeed = UserProfile.InfoDungeon.GetRequireAttrByStr(testType, biasData); Script = string.Format("|icon.oth1||进行{0}考验|lime|(判定{1} {2:0.0}%胜率)", GetTestAttrStr(testType), attrNeed, GetWinRate(UserProfile.InfoDungeon.GetAttrByStr(testType) + 0.5f, attrNeed)); } else //因为convert了 { Script = string.Format("|icon.oth1||进行运气考验|lime|(判定{0} {1:0.0}%胜率)", 3 + biasData, GetWinRate(3.5f, 3 + biasData)); } } } else if (parms[0] == "hasditem") { var itemId = DungeonBook.GetDungeonItemId(config.NeedDungeonItemId); Disabled = UserProfile.InfoDungeon.GetDungeonItemCount(itemId) < config.NeedDungeonItemCount; } else if (parms[0] == "hasdna") { if (config.DnaInfo != null && config.DnaInfo.Length > 0) { string dnaStr = ""; int dnaId = 0; foreach (var dnaName in config.DnaInfo) { var nowId = DnaBook.GetDnaId(dnaName); dnaId |= (int)Math.Pow(2, nowId); dnaStr += ConfigData.GetPlayerDnaConfig(nowId).Name + " "; } Script = string.Format("|icon.oth14||{0}|lime|(DNA限定{1})", Script, dnaStr); Disabled = !UserProfile.InfoBasic.HasDna(dnaId); } } }