private static void GetFarmHouseSpouseRooms(FarmHouse fh, List <string> orderableSpouses, out List <string> orderedSpouses, out List <string> customSpouses) { SMonitor.Log($"Getting {orderableSpouses.Count} spouse rooms"); customSpouses = new List <string>(); for (int i = orderableSpouses.Count - 1; i >= 0; i--) { if (ModEntry.customRoomData.TryGetValue(orderableSpouses[i], out SpouseRoomData srd) && !srd.islandFarmHouse && (srd.upgradeLevel == fh.upgradeLevel || srd.upgradeLevel < 0) && srd.startPos.X > -1) { SMonitor.Log($"{orderableSpouses[i]} has custom spouse room"); customSpouses.Add(orderableSpouses[i]); orderableSpouses.RemoveAt(i); } } orderedSpouses = new List <string>(); string[] roomOrder = Config.SpouseRoomOrder.Split(','); foreach (string str in roomOrder) { string s = str.Trim(); if (orderableSpouses.Contains(s)) { SMonitor.Log($"{s} has custom room order"); orderedSpouses.Add(s); orderableSpouses.Remove(s); } } foreach (string str in orderableSpouses) { SMonitor.Log($"{str} has no customization"); orderedSpouses.Add(str); Config.SpouseRoomOrder += (Config.SpouseRoomOrder.Trim().Length > 0 ? "," : "") + str; } SHelper.WriteConfig(Config); }
protected override void Awake() { base.Awake(); coneAngle = SMath.ClampDegree0To360(coneAngle); faceAngle = SMath.ClampDegree0To360(faceAngle); var meshFilter = GetComponent <MeshFilter>(); if (meshFilter == null) { meshFilter = gameObject.AddComponent <MeshFilter>(); } if (_mesh == null) { _mesh = new Mesh(); meshFilter.mesh = _mesh; } _losCamera = LOSManager.instance.losCamera; Vector2 screenSize = SHelper.GetScreenSizeInWorld(_losCamera.unityCamera); _raycastDistance = Mathf.Sqrt(screenSize.x * screenSize.x + screenSize.y * screenSize.y); }
public static List <string> ReorderSpousesForSleeping(List <string> sleepSpouses) { List <string> configSpouses = Config.SpouseSleepOrder.Split(',').Where(s => s.Length > 0).ToList(); List <string> spouses = new List <string>(); foreach (string s in configSpouses) { if (sleepSpouses.Contains(s)) { spouses.Add(s); } } foreach (string s in sleepSpouses) { if (!spouses.Contains(s)) { spouses.Add(s); configSpouses.Add(s); } } string configString = string.Join(",", configSpouses); if (configString != Config.SpouseSleepOrder) { Config.SpouseSleepOrder = configString; SHelper.WriteConfig(Config); } return(spouses); }
public Boolean Register(String login, String password) { var authData = new CAuthorizationData(login, password); HttpResponseMessage response = SHelper.PostRaw("api/Authorization/Registration", authData); return(response.IsSuccessStatusCode); }
public override bool CheckDirty() { bool withinScreen = SHelper.CheckWithinScreen(position, _losCamera.unityCamera, _radius) || !Application.isPlaying; bool dirty = withinScreen && ((base.CheckDirty() || _radius != _previousRadius || _radius != radius) && radius > 0); dirty = dirty || (withinScreen && !_withinScreen); _withinScreen = withinScreen; return(dirty); }
public Boolean TryAuthorize(String login, String password, out CAuthToken token) { var authData = new CAuthorizationData(login, password); HttpResponseMessage response = SHelper.PostRaw("api/Authorization/Login", authData); if (response.IsSuccessStatusCode && response.StatusCode == HttpStatusCode.OK) { String result = response.Content.ReadAsStringAsync().Result; token = JsonConvert.DeserializeObject <CAuthToken>(result); return(true); } token = null; return(false); }
public void UpdateViewingBox() { Vector2 screenSize = SHelper.GetScreenSizeInWorld(unityCamera); halfViewboxSize = screenSize / 2 * LOSManager.instance.viewboxExtension; Vector2 upperRight = new Vector2(halfViewboxSize.x, halfViewboxSize.y) + SMath.Vec3ToVec2(_trans.position); Vector2 upperLeft = new Vector2(-halfViewboxSize.x, halfViewboxSize.y) + SMath.Vec3ToVec2(_trans.position); Vector2 lowerLeft = new Vector2(-halfViewboxSize.x, -halfViewboxSize.y) + SMath.Vec3ToVec2(_trans.position); Vector2 lowerRight = new Vector2(halfViewboxSize.x, -halfViewboxSize.y) + SMath.Vec3ToVec2(_trans.position); viewbox[0].SetStartEnd(lowerRight, upperRight); // right viewbox[1].SetStartEnd(upperRight, upperLeft); // up viewbox[2].SetStartEnd(upperLeft, lowerLeft); // left viewbox[3].SetStartEnd(lowerLeft, lowerRight); // down }
public override void OnInspectorGUI() { var light = (LOSFullScreenLight)target; if (!SHelper.CheckWithinScreen(light.transform.position, LOSManager.instance.losCamera.unityCamera, 0)) { EditorGUILayout.HelpBox( "Full Screen Light requires its position within the camera. " + "Otherwise, wired shadow will be present. I'm working on the next version to better solve the issue.", MessageType.Warning); } base.OnInspectorGUI(); EditorGUILayout.PropertyField(_invertMode); serializedObject.ApplyModifiedProperties(); }
void Update() { int mouseButton = -1; if (Input.GetMouseButtonDown(0)) { mouseButton = 0; } else if (Input.GetMouseButtonDown(1)) { mouseButton = 1; } if (mouseButton != -1) { Vector3 mousePosition = SHelper.GetMousePositionInWorld(); if (mouseButton == 0) { _goblinTrans = _goblinTrans == null ? (GameObject.Instantiate(Resources.Load("Goblin")) as GameObject).transform : _goblinTrans; _goblinTrans.name = "Goblin"; _goblinTrans.transform.position = mousePosition; } else if (mouseButton == 1) { _orcTrans = _orcTrans == null ? (GameObject.Instantiate(Resources.Load("Orc")) as GameObject).transform : _orcTrans; _orcTrans.name = "Orc"; _orcTrans.transform.position = mousePosition; } } if (Input.GetKeyDown(KeyCode.R) || Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.Space)) { Application.LoadLevel(0); } if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } }
public void Process(List <LOSEventTrigger> triggers) { RaycastHit hit; List <LOSEventTrigger> triggeredTriggers = new List <LOSEventTrigger>(); List <LOSEventTrigger> notTriggeredTriggers = new List <LOSEventTrigger>(); foreach (LOSEventTrigger trigger in triggers) { if (!SHelper.CheckGameObjectInLayer(trigger.gameObject, triggerLayers)) { continue; } bool triggered = false; Vector3 direction = trigger.position - _trans.position; if (direction.sqrMagnitude <= distance * distance) // Within distance { if (triggeredTriggers.Contains(trigger)) { continue; // May be added previously } LayerMask mask = 1 << trigger.gameObject.layer | obstacleLayers; if (Physics.Raycast(_trans.position, direction, out hit, distance, mask)) { GameObject hitGo = hit.collider.gameObject; if (hitGo == trigger.gameObject) { triggered = true; } else if (hitGo.layer == trigger.gameObject.layer) { LOSEventTrigger triggerToAdd = hitGo.GetComponentInChildren <LOSEventTrigger>(); if (triggerToAdd == null) { triggerToAdd = hitGo.GetComponentInParent <LOSEventTrigger>(); } triggeredTriggers.Add(triggerToAdd); } } } if (triggered) { triggeredTriggers.Add(trigger); } else { notTriggeredTriggers.Add(trigger); } } foreach (LOSEventTrigger trigger in triggeredTriggers) { trigger.TriggeredBySource(this); } foreach (LOSEventTrigger trigger in notTriggeredTriggers) { trigger.NotTriggeredBySource(this); } }
public bool CheckWithinScreen() { return(SHelper.CheckWithinScreen(_trans.position, LOSManager.instance.GetLosCamera(LosCameraIndex).unityCamera, 5)); }
public void Process(List <LOSEventTrigger> triggers) { RaycastHit2D hit; List <LOSEventTrigger> triggeredTriggers = new List <LOSEventTrigger>(); List <LOSEventTrigger> notTriggeredTriggers = new List <LOSEventTrigger>(); foreach (LOSEventTrigger trigger in triggers) { if (!SHelper.CheckGameObjectInLayer(trigger.gameObject, triggerLayers)) { continue; } bool triggered = false; Vector3 direction = trigger.position - _trans.position; float degree = SMath.VectorToDegree(direction); if (lightSource != null) { if (!lightSource.CheckDegreeWithinCone(degree)) { notTriggeredTriggers.Add(trigger); continue; } } if (direction.sqrMagnitude <= distance * distance) // Within distance { if (triggeredTriggers.Contains(trigger)) { continue; // May be added previously } LayerMask mask = 1 << trigger.gameObject.layer | obstacleLayers; /*if (Physics2D.Raycast(_trans.position, direction, out hit, distance, mask)) { * GameObject hitGo = hit.collider.gameObject; * * if (hitGo == trigger.gameObject) { * triggered = true; * } * else if (hitGo.layer == trigger.gameObject.layer) { * LOSEventTrigger triggerToAdd = hitGo.GetComponentInChildren<LOSEventTrigger>(); * if (triggerToAdd == null) { * triggerToAdd = hitGo.GetComponentInParent<LOSEventTrigger>(); * } * triggeredTriggers.Add(triggerToAdd); * } * }*/ hit = Physics2D.Raycast(_trans.position, direction, distance, mask); if (hit.collider != null) { GameObject hitGo = hit.collider.gameObject; if (hitGo == trigger.gameObject) { triggered = true; } else if (hitGo.layer == trigger.gameObject.layer) { LOSEventTrigger triggerToAdd = hitGo.GetComponentInChildren <LOSEventTrigger>(); if (triggerToAdd == null) { triggerToAdd = hitGo.GetComponentInParent <LOSEventTrigger>(); } triggeredTriggers.Add(triggerToAdd); } } } if (triggered) { triggeredTriggers.Add(trigger); } else { notTriggeredTriggers.Add(trigger); } } List <LOSEventTrigger> newTriggers = new List <LOSEventTrigger>(); foreach (LOSEventTrigger trigger in triggeredTriggers) { trigger.TriggeredBySource(this); if (!_triggeredTriggers.Contains(trigger)) { newTriggers.Add(trigger); } } if (OnNewTriggersDetected != null && newTriggers.Count > 0) { OnNewTriggersDetected(newTriggers); } List <LOSEventTrigger> triggersExit = new List <LOSEventTrigger>(); foreach (LOSEventTrigger trigger in _triggeredTriggers) { if (!triggeredTriggers.Contains(trigger)) { triggersExit.Add(trigger); } } if (OnTriggersExitDetected != null && triggersExit.Count > 0) { OnTriggersExitDetected(triggersExit); } foreach (LOSEventTrigger trigger in notTriggeredTriggers) { trigger.NotTriggeredBySource(this); } _triggeredTriggers = triggeredTriggers; }
public override bool CheckDirty() { return(SHelper.CheckWithinScreen(position, LOSManager.instance.losCamera.unityCamera, offScreenDistance) && (base.CheckDirty() || gameObject.layer != _previousLayerMask)); }
public void Process(List <LOSEventTrigger> triggers) { RaycastHit hit; List <LOSEventTrigger> triggeredTriggers = new List <LOSEventTrigger>(); List <LOSEventTrigger> notTriggeredTriggers = new List <LOSEventTrigger>(); foreach (LOSEventTrigger trigger in triggers) { if (!SHelper.CheckGameObjectInLayer(trigger.gameObject, triggerLayers)) { continue; } bool triggered = false; Vector3 direction = trigger.position - _trans.position; float degree = SMath.VectorToDegree(direction); if (lightSource != null) { if (!lightSource.CheckDegreeWithinCone(degree)) { notTriggeredTriggers.Add(trigger); continue; } } if (direction.sqrMagnitude <= distance * distance) // Within distance { if (triggeredTriggers.Contains(trigger)) { continue; // May be added previously } LayerMask mask = 1 << trigger.gameObject.layer | obstacleLayers; //Custom addition for 2d raycasting if (LOSManager.instance.physicsOpt == LOSManager.PhysicsOpt.Physics_2D) { RaycastHit2D rayHit2D = Physics2D.Raycast(_trans.position, direction, distance, mask);; //List<Vector3> triggerExtents = trigger.GetComponent<Collider2D>().s; List <int> degreeOffsets = new List <int> { 1, -1, 2, -2, 4, -4, 8, -8, 16, -16, 32, -32 }; if (rayHit2D.collider == null || rayHit2D.collider.gameObject != trigger.gameObject) { foreach (int degreeOffset in degreeOffsets) { direction = SMath.DegreeToUnitVector(degree + degreeOffset); rayHit2D = Physics2D.Raycast(_trans.position, direction, distance, mask); if (rayHit2D.collider != null && rayHit2D.collider.gameObject == trigger.gameObject) { break; } } } if (rayHit2D.collider != null) { GameObject hitGo = rayHit2D.collider.gameObject; if (hitGo == trigger.gameObject) { Debug.DrawRay(_trans.position, direction * 15f, Color.red, 0.2f); triggered = true; } else if (hitGo.layer == trigger.gameObject.layer) { LOSEventTrigger triggerToAdd = hitGo.GetComponentInChildren <LOSEventTrigger>(); if (triggerToAdd == null) { triggerToAdd = hitGo.GetComponentInParent <LOSEventTrigger>(); } if (triggerToAdd != null) { triggeredTriggers.Add(triggerToAdd); } } } } else { if (Physics.Raycast(_trans.position, direction, out hit, distance, mask)) { GameObject hitGo = hit.collider.gameObject; if (hitGo == trigger.gameObject) { triggered = true; } else if (hitGo.layer == trigger.gameObject.layer) { LOSEventTrigger triggerToAdd = hitGo.GetComponentInChildren <LOSEventTrigger>(); if (triggerToAdd == null) { triggerToAdd = hitGo.GetComponentInParent <LOSEventTrigger>(); } if (triggerToAdd != null) { triggeredTriggers.Add(triggerToAdd); } } } } } if (triggered) { triggeredTriggers.Add(trigger); } else { notTriggeredTriggers.Add(trigger); } } List <LOSEventTrigger> newTriggers = new List <LOSEventTrigger>(); foreach (LOSEventTrigger trigger in triggeredTriggers) { trigger.TriggeredBySource(this); if (!_triggeredTriggers.Contains(trigger)) { newTriggers.Add(trigger); } } if (OnNewTriggersDetected != null && newTriggers.Count > 0) { OnNewTriggersDetected(newTriggers); } List <LOSEventTrigger> triggersExit = new List <LOSEventTrigger>(); foreach (LOSEventTrigger trigger in _triggeredTriggers) { if (!triggeredTriggers.Contains(trigger)) { triggersExit.Add(trigger); } } if (OnTriggersExitDetected != null && triggersExit.Count > 0) { OnTriggersExitDetected(triggersExit); } foreach (LOSEventTrigger trigger in notTriggeredTriggers) { trigger.NotTriggeredBySource(this); } _triggeredTriggers = triggeredTriggers; }
public override bool CheckDirty() { bool withinScreen = SHelper.CheckWithinScreen(position, LOSManager.instance.losCamera.unityCamera, _radius); return(withinScreen && ((base.CheckDirty() || _radius != _previousRadius || _radius != radius) && radius > 0)); }
public static bool Toolbar_draw_prefix(Toolbar __instance, SpriteBatch b, ref float ___transparency, List <ClickableComponent> ___buttons, ref Item ___hoverItem) { if (!Config.EnableMod) { return(true); } if (Game1.activeClickableMenu != null && !Config.ShowWithActiveMenu) { return(false); } float scale = 1f; int breadth = (int)Math.Round(800 * scale); int girth = (int)Math.Round(96 * scale); Point playerGlobalPos = Game1.player.GetBoundingBox().Center; Vector2 playerGlobalVec = new Vector2(playerGlobalPos.X, playerGlobalPos.Y); Vector2 playerLocalVec = Game1.GlobalToLocal(Game1.viewport, playerGlobalVec); int marginX = Utility.makeSafeMarginX(8); int marginY = Utility.makeSafeMarginY(8); Point newPos = new Point(__instance.xPositionOnScreen, __instance.yPositionOnScreen); if (Game1.options.pinToolbarToggle) { ___transparency = Math.Min(1f, ___transparency + 0.075f); bool transparent; switch (Config.PinnedPosition) { case "bottom": transparent = playerLocalVec.Y > Game1.viewport.Height - girth - Config.MarginY; __instance.yPositionOnScreen = Game1.uiViewport.Height - girth - Config.MarginY; __instance.yPositionOnScreen += 8; __instance.yPositionOnScreen -= marginY; __instance.xPositionOnScreen = Game1.uiViewport.Width / 2 - breadth / 2 + Config.OffsetX; break; case "left": transparent = playerLocalVec.X < 96 + Config.MarginX; __instance.xPositionOnScreen = Config.MarginX; __instance.xPositionOnScreen -= 8; __instance.xPositionOnScreen += marginY; __instance.yPositionOnScreen = Game1.uiViewport.Height / 2 - breadth / 2 + Config.OffsetY; break; case "right": transparent = playerLocalVec.X > Game1.viewport.Width - girth - Config.MarginX; __instance.xPositionOnScreen = Game1.uiViewport.Width - girth - Config.MarginX; __instance.xPositionOnScreen += 8; __instance.xPositionOnScreen -= marginY; __instance.yPositionOnScreen = Game1.uiViewport.Height / 2 - breadth / 2 + Config.OffsetY; break; case "top": transparent = playerLocalVec.Y < 96 + Config.MarginY; __instance.yPositionOnScreen = Config.MarginY; __instance.yPositionOnScreen -= 8; __instance.yPositionOnScreen += marginY; __instance.xPositionOnScreen = Game1.uiViewport.Width / 2 - breadth / 2 + Config.OffsetX; break; default: transparent = false; break; } if (transparent) { ___transparency = Math.Max(0.33f, ___transparency - 0.15f); } } else if (__instance.xPositionOnScreen == -1 && __instance.yPositionOnScreen == -1) { if (Config.Vertical) { __instance.xPositionOnScreen = Config.MarginX; __instance.xPositionOnScreen -= 8; __instance.xPositionOnScreen += marginX; __instance.yPositionOnScreen = Game1.uiViewport.Height / 2 - breadth / 2 + Config.OffsetY; } else { __instance.yPositionOnScreen = Game1.uiViewport.Height - girth - Config.MarginY; __instance.yPositionOnScreen += 8; __instance.yPositionOnScreen -= marginY; __instance.xPositionOnScreen = Game1.uiViewport.Width / 2 - breadth / 2 + Config.OffsetX; } } else if (Config.Vertical) { if (Config.SetPosition) { if (playerLocalVec.X > Game1.viewport.Width / 2 + 32) { __instance.xPositionOnScreen = Config.MarginX; __instance.xPositionOnScreen -= 8; __instance.xPositionOnScreen += marginX; } else { __instance.xPositionOnScreen = Game1.uiViewport.Width - girth - Config.MarginX; __instance.xPositionOnScreen += 8; __instance.xPositionOnScreen -= marginX; } __instance.yPositionOnScreen = Game1.uiViewport.Height / 2 - breadth / 2 + Config.OffsetY; } ___transparency = 1f; } else { if (Config.SetPosition) { if (playerLocalVec.Y > Game1.viewport.Height / 2 + 64) { __instance.yPositionOnScreen = Config.MarginY; __instance.yPositionOnScreen -= 8; __instance.yPositionOnScreen += marginY; } else { __instance.yPositionOnScreen = Game1.uiViewport.Height - girth - Config.MarginY; __instance.yPositionOnScreen += 8; __instance.yPositionOnScreen -= marginY; } __instance.xPositionOnScreen = Game1.uiViewport.Width / 2 - breadth / 2 + Config.OffsetX; __instance.xPositionOnScreen -= 8; __instance.xPositionOnScreen += marginX; } ___transparency = 1f; } if (Config.Vertical) { __instance.width = girth; __instance.height = breadth; } else { __instance.width = breadth; __instance.height = girth; } if (!Config.SetPosition) { if (__instance.xPositionOnScreen != Config.PositionX || Config.PositionY != __instance.yPositionOnScreen) { Config.PositionX = __instance.xPositionOnScreen; Config.PositionY = __instance.yPositionOnScreen; SHelper.WriteConfig(Config); } } IClickableMenu.drawTextureBox(b, Game1.menuTexture, __instance.toolbarTextSource, __instance.xPositionOnScreen, __instance.yPositionOnScreen, (int)Math.Round(scale * (Config.Vertical ? 96 : 800)), (int)Math.Round(scale * (Config.Vertical ? 800 : 96)), Color.White * ___transparency, 1f, false, -1f); for (int i = 0; i < 12; i++) { Vector2 toDraw; if (Config.Vertical) { toDraw = new Vector2(__instance.xPositionOnScreen + 16 * scale, __instance.yPositionOnScreen + (16 + i * 64) * scale); } else { toDraw = new Vector2(__instance.xPositionOnScreen + (16 + i * 64) * scale, __instance.yPositionOnScreen + 16 * scale); } b.Draw(Game1.menuTexture, toDraw, new Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.menuTexture, (Game1.player.CurrentToolIndex == i) ? 56 : 10, -1, -1)), Color.White * ___transparency, 0, Vector2.Zero, scale, SpriteEffects.None, 0.87f); if (!Game1.options.gamepadControls) { b.DrawString(Game1.tinyFont, __instance.slotText[i], toDraw + new Vector2(4f, -8f), Color.DimGray * ___transparency, 0, Vector2.Zero, scale, SpriteEffects.None, 0.88f); } } for (int i = 0; i < 12; i++) { Vector2 toDraw; Rectangle rect; if (Config.Vertical) { rect = new Rectangle((int)Math.Round(__instance.xPositionOnScreen + 16 * scale), (int)Math.Round(__instance.yPositionOnScreen + (16 + i * 64) * scale), (int)Math.Round(64 * scale), (int)Math.Round(64 * scale)); toDraw = new Vector2(__instance.xPositionOnScreen + 16 * scale, __instance.yPositionOnScreen + (16 + i * 64) * scale); } else { rect = new Rectangle((int)Math.Round(__instance.xPositionOnScreen + (16 + i * 64) * scale), (int)Math.Round(__instance.yPositionOnScreen + 16 * scale), (int)Math.Round(64 * scale), (int)Math.Round(64 * scale)); toDraw = new Vector2(__instance.xPositionOnScreen + (16 + i * 64) * scale, __instance.yPositionOnScreen + 16 * scale); } ___buttons[i].bounds = rect; ___buttons[i].scale = Math.Max(1f, ___buttons[i].scale - 0.025f); if (Game1.player.Items.Count > i && Game1.player.Items.ElementAt(i) != null) { /* * var ptr = AccessTools.Method(typeof(Tool), "drawInMenu", new Type[] { typeof(SpriteBatch), typeof(Vector2), typeof(float), typeof(float), typeof(float) }).MethodHandle.GetFunctionPointer(); * var baseMethod = (Func<SpriteBatch, Vector2, float, float, float, Item>)Activator.CreateInstance(typeof(Func<SpriteBatch, Vector2, float, float, float, Item>), __instance, ptr); * baseMethod(b, toDraw, ((Game1.player.CurrentToolIndex == i) ? 0.9f : (___buttons.ElementAt(i).scale * 0.8f)) * scale, ___transparency, 0.88f); */ Game1.player.Items[i].drawInMenu(b, toDraw, ((Game1.player.CurrentToolIndex == i) ? 0.9f : (___buttons.ElementAt(i).scale * 0.8f)) * scale, ___transparency, 0.88f); } } if (___hoverItem != null) { IClickableMenu.drawToolTip(b, ___hoverItem.getDescription(), ___hoverItem.DisplayName, ___hoverItem, false, -1, 0, -1, -1, null, -1); ___hoverItem = null; } return(false); }
protected float GetMinRaycastDistance() { Vector3 screenSize = SHelper.GetScreenSizeInWorld(_losCamera.unityCamera); return(screenSize.magnitude); }
public override bool CheckDirty() { bool withinScreen = SHelper.CheckWithinScreen(position, LOSManager.instance.losCamera.unityCamera, offScreenDistance) || !Application.isPlaying; return(withinScreen && (base.CheckDirty() || gameObject.layer != _previousLayerMask)); }
public IEnumerable <CHeroData> GetHeroes() { var data = SHelper.Get <CHeroData[]>("api/heroes"); return(data); }