private void refreshArrays() { for (int i = 0; i < allLocalOwned.Count; i++) { NetPosition currentNetPos = allLocalOwned[i]; if (currentNetPos != null && currentNetPos.active && (currentNetPos.myFlow.localOwned || currentNetPos.myFlow.isLocalPlayer)) { // I can't be arsed to figure out what the reverse of the above would be, without just a cheeky ! at the beginning } else { allLocalOwned.RemoveAt(i); i--; } } if (allLocalOwned.Count != prevArraySize) { prevArraySize = allLocalOwned.Count; idArr = new int[prevArraySize]; targetPosArr = new Vector3[prevArraySize]; targetRotArr = new Quaternion[prevArraySize]; targetVelArr = new Vector3[prevArraySize]; originLifeTimeArr = new float[prevArraySize]; } }
void pulseAllPositions() { if (allLocalOwned.Count > 0) { //List<int> idList = new List<int>(); //List<Vector3> targetPosList = new List<Vector3>(); //List<Quaternion> targetRotList = new List<Quaternion>(); //List<Vector3> targetVelList = new List<Vector3>(); //List<float> originLifeTimeList = new List<float>(); //for (int i = 0; i < allLocalOwned.Count; i++) //{ // NetPosition currentNetPos = allLocalOwned[i]; // if (currentNetPos != null && currentNetPos.active && (currentNetPos.myFlow.localOwned || currentNetPos.myFlow.isLocalPlayer)) // { // idList.Add(currentNetPos.photonView.ViewID); // targetPosList.Add(currentNetPos.transform.position); // targetRotList.Add(currentNetPos.transform.rotation); // targetVelList.Add(currentNetPos.myRB.velocity); // originLifeTimeList.Add(currentNetPos.lifeTime); // } // else // { // allLocalOwned.RemoveAt(i); // i--; // } //} //photonView.RPC("rpcPulsePositions", RpcTarget.Others, // idList.ToArray(), targetPosList.ToArray(), targetRotList.ToArray(), // targetVelList.ToArray(), originLifeTimeList.ToArray()); refreshArrays(); for (int i = 0; i < prevArraySize; i++) { NetPosition currentNetPos = allLocalOwned[i]; if (currentNetPos != null) { idArr[i] = currentNetPos.photonView.ViewID; targetPosArr[i] = currentNetPos.transform.position; targetRotArr[i] = currentNetPos.transform.rotation; targetVelArr[i] = currentNetPos.myRB.velocity; originLifeTimeArr[i] = currentNetPos.lifeTime; } else { idArr[i] = -1; // signal that this index is bad. Prevent receiving end from going kaput } } photonView.RPC("rpcPulsePositions", RpcTarget.Others, idArr, targetPosArr, targetRotArr, targetVelArr, originLifeTimeArr); } }
private void Engage() { NetPosition position = Game1.player.position; buff = Game1.player.temporarySpeedBuff + config.initialSpeedBoost; Debug($"{Game1.player.Name} engaged heelies at {position.X} {position.Y} | Speed buff: {buff}"); isRolling = true; }
private void Disengage() { isRolling = false; Game1.player.completelyStopAnimatingOrDoingAction(); NetPosition position = Game1.player.position; Debug($"{Game1.player.Name} released heelies at {position.X} {position.Y}"); }
private void CloseCurrentOrderForNet(NetPosition position) { CalculateCurrentLoseStreak(position.Profit); if (OpenMarketOrder(position.Side == OrderSide.Buy ? OrderSide.Sell : OrderSide.Buy, position.Volume).ResultCode == OrderCmdResultCodes.Ok) { Print($"Close volume = {position.Volume}"); } }
private void CloseCurrentOrderForNet(NetPosition position) { CalculateCurrentLoseStreak(position.Profit); var side = position.Side == OrderSide.Buy ? OrderSide.Sell : OrderSide.Buy; var price = side == OrderSide.Buy ? Ask : Bid; if (OpenOrder(symbol: Symbol.Name, type: OrderType.Market, side: side, volume: position.Volume, price: price, maxVisibleVolume: null, stopPrice: null).ResultCode == OrderCmdResultCodes.Ok) { Print($"Close volume = {position.Volume}, price = {price}"); } }
public static Vector2 GetFloatingPosition(NetPosition position) { if (RecentDebris?.IsAnItem() == true) //if this chunk's debris represents an item { Vector2 tilePosition = new Vector2((int)(position.X / 64.0) + 1, (int)(position.Y / 64.0) + 1); //get this chunk's tile position if (Game1.player.currentLocation.doesTileSinkDebris((int)tilePosition.X, (int)tilePosition.Y, RecentDebris.debrisType)) //if this chunk is floating (i.e. should sink on its current tile) { int offset = (int)(Math.Sin((double)((Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 2500.0) + (position.X * 5)) / 2500.0 * (2.0 * Math.PI)) * 6.0); //calculate this chunk's offset return(new Vector2((int)position.X, position.Y + offset)); //return the chunk's position with the offset added to its Y value } } //if this chunk is NOT floating return(position.Value); //return the chunk's actual position }
public void rpcPulsePositions(int[] IDs, Vector3[] targetPositions, Quaternion[] targetRots, Vector3[] targetVels, float[] originLifeTimes) { //Debug.LogError("NetPosition pulse received! with size " + IDs.Length); for (int i = 0; i < IDs.Length; i++) { PhotonView currentView = PhotonNetwork.GetPhotonView(IDs[i]); //Debug.LogWarning("============ Entering rpc pulse loop iteration"); if (currentView != null && IDs[i] != -1) // the -1 check may be reduntant. Leaving it in just in case { NetPosition currentNetPosition = currentView.GetComponent <NetPosition>(); //Debug.LogWarning("************ photonView found, updating current position"); currentNetPosition.updatePositionAndVelocity(targetPositions[i], targetRots[i], targetVels[i], originLifeTimes[i]); } } }
private IEnumerable <NetPosition> parseOuputNetPositions(String netPositionFileFullPath) { List <NetPosition> netPositions = new List <NetPosition>(); using (StreamReader streamreader = File.OpenText(netPositionFileFullPath)) { string line = streamreader.ReadLine(); //discard header file while ((line = streamreader.ReadLine()) != null) { string[] fields = line.Split(","); NetPosition netPosition = new NetPosition(fields[0], fields[1], Convert.ToDecimal(fields[2])); netPositions.Add(netPosition); } } return(netPositions); }
public IEnumerable <NetPosition> calculateNetPositions(IEnumerable <Position> positions) { //aggregate the positions by trader+symbol to calculate the net positions var posMapByTraderAndSymbol = new Dictionary <Tuple <string /*trader*/, string /*symbol*/>, decimal /*qty*/>(); foreach (Position position in positions) { Decimal netQty; var traderSymbolTuple = new Tuple <String, String>(position.Trader, position.Symbol); if (posMapByTraderAndSymbol.TryGetValue(new Tuple <string, string>(position.Trader, position.Symbol), out netQty)) { posMapByTraderAndSymbol[traderSymbolTuple] = netQty + position.Qty; } else { posMapByTraderAndSymbol.Add(traderSymbolTuple, position.Qty); } } //flatten out the map to an array of positions to return. //ordering is undefined var netPositions = new List <NetPosition>(); foreach (KeyValuePair <Tuple <String, String>, Decimal> kvp in posMapByTraderAndSymbol) { var netPosition = new NetPosition(kvp.Key.Item1, //trader kvp.Key.Item2, //symbol kvp.Value //netQty ); netPositions.Add(netPosition); } return(netPositions); }
public static PositionState ParsePosition(NetPosition position, DateTime time) { return(new PositionState(time, position.Symbol, position.Side, position.Volume)); }
///設定網子狀態資訊 private void setNetInfo(NetPosition netPos, bool haveLava) { switch(netPos) { case NetPosition.TOP_LEFT: { isHaveLava[0] = haveLava; break; } case NetPosition.TOP_RIGHT: { isHaveLava[1] = haveLava; break; } case NetPosition.BOTTOM_LEFT: { isHaveLava[2] = haveLava; break; } case NetPosition.BOTTOM_RIGHT: { isHaveLava[3] = haveLava; break; } } }
///取得網子狀態資訊 private bool getNetInfo(NetPosition netPos) { bool returnInfo = false; switch(netPos) { case NetPosition.TOP_LEFT: { returnInfo = isHaveLava[0]; break; } case NetPosition.TOP_RIGHT: { returnInfo = isHaveLava[1]; break; } case NetPosition.BOTTOM_LEFT: { returnInfo = isHaveLava[2]; break; } case NetPosition.BOTTOM_RIGHT: { returnInfo = isHaveLava[3]; break; } } return returnInfo; }
public void reportAsOwned(NetPosition netPosScript) { allLocalOwned.Add(netPosScript); }
/// <summary>Patch for Rascal chance to recover ammunition.</summary> private static void ProjectileBehaviorOnCollisionPostfix(ref Projectile __instance, ref NetInt ___currentTileSheetIndex, ref NetPosition ___position, ref NetCharacterRef ___theOneWhoFiredMe, GameLocation location) { try { if (__instance is not BasicProjectile) { return; } var firer = ___theOneWhoFiredMe.Get(location) is Farmer ? (Farmer)___theOneWhoFiredMe.Get(location) : Game1.player; if (!Utility.SpecificPlayerHasProfession("Rascal", firer)) { return; } if (Utility.IsMineralAmmunition(___currentTileSheetIndex.Value) && Game1.random.NextDouble() < 0.6 || ___currentTileSheetIndex.Value == SObject.wood + 1 && Game1.random.NextDouble() < 0.3) { location.debris.Add(new Debris(___currentTileSheetIndex.Value - 1, new Vector2((int)___position.X, (int)___position.Y), firer.getStandingPosition())); } } catch (Exception ex) { Monitor.Log($"Failed in {nameof(ProjectileBehaviorOnCollisionPostfix)}:\n{ex}"); } }