private void ProcessInputPacket(InputPacket packet) { foreach (PlayerInput i in packet.inputs) { ProcessInput(i); } }
// TODO checks public ParameterList(InputPacket packet) { super(0); // array lists in which store parameters ArrayList parameters = new ArrayList(); bool stop = false; do { // at least 4 bytes for length and type if (packet.getCursorPosition() + 4 <= packet.getLength()) { short parameterId = packet.read_short(); short length = packet.read_short(); byte[] p = new byte[length]; if (parameterId != PID_SENTINEL) { for (int i=0; i<length; i++) { p[i] = packet.read_octet(); } parameters.add(new Parameter(parameterId,length,p)); } else { stop = true; } } else { throw new MalformedSubmessageElementException("ParameterList too short"); } } while (!stop); value = new Parameter[parameters.size()]; parameters.toArray(value); }
internal void Update() { InputPacket ip = new InputPacket(); if (GetComponent <CharacterBase>() == null || GetComponent <CharacterBase>().IsAutonomous) { updateCustomControl(); ip = m_currentControl.BaseMovement(); } else { m_inputMove = new Vector2(0f, 0f); } /*if (m_FootStepInfo.PlayFootsteps) * playStepSounds(); */ moveSmoothly(); currentPlayerControl(ip); processExtraMovement(); if (m_inputMove != m_lastInput) { updateAverageVelocity(); } m_lastInput = m_inputMove; resetJumps(); updateAverageVelocity(); }
public override InputPacket AITemplate() { InputPacket ip = new InputPacket(); float t = Time.timeSinceLevelLoad; if (m_targetObj != null && t > m_nextMoveOKTime) { float moddedOffX = (m_targetObj.transform.position.x > transform.position.x) ? TargetOffset.x : -TargetOffset.x; float moddedOffZ = (m_targetObj.transform.position.z > transform.position.z) ? TargetOffset.z : -TargetOffset.z; Vector3 target = new Vector3(m_targetObj.transform.position.x + moddedOffX, 0f, m_targetObj.transform.position.z + moddedOffZ); float d = Vector3.Distance(target, transform.position); if (d > TargetTolerance) { ip.movementInput = new Vector2((target.x > transform.position.x) ? 1f : -1f, (target.z > transform.position.z) ? 1f : -1f); } if (t < m_jumpingHoldTime) { ip.jump = true; } if (JumpProbabilityPercent > 0.0f && t > m_nextJumpTime && d < JumpWhenInProximityOf) { m_nextJumpTime = t + JumpCheckInterval; if (Random.Range(0, 100) < JumpProbabilityPercent) { m_jumpingHoldTime = t + 0.5f; //Debug.Log("Trying to Jump"); } } } return(ip); }
void Start() { rgd = GetComponent <Rigidbody2D>(); ip = new InputPacket(); input = GetComponent <AIScript>(); Debug.Log(input); }
IEnumerator WaitAndSendData() { // ConnectionManager.Instance.isFriendLive = false; if (myCurrTurnInput.Count <= 0) { tryCount = 0; StopCoroutine("WaitAndSendData"); ConnectionManager.Instance.isFriendLive = true; if (UIManager.instance.gameOverLocal) { ConnectionManager.Instance.OnGameOverSendData(ConnectionManager.Instance.myID); } yield break; // ConnectionManager.Instance.connectionMsg.text = ""; } if (myCurrTurnInput.Count > 0) { tryCount++; InputPacket ip = myCurrTurnInput.Peek(); Debug.Log("Data mised Send Again" + ip.input); ConnectionManager.Instance.OnSendMeAnswer(ip.input + " " + ip.packetID); if (tryCount > 3) { FriendNetStatus(); } } yield return(new WaitForSeconds(4f)); StartCoroutine("WaitAndSendData"); }
public void OnInputTaken(int pData) { Debug.Log("Current Input >>> " + pData); if (GameManager.instance.isTimeUp) { return; } if (!GameManager.instance.isAllowPlay) { QuitGame(); } AudioManager.Instance.PlaySound(AudioManager.SoundType.ButtonClick); if (GameManager.instance.currGameMode == eGameMode.vServerMulltiPlayer && GameManager.instance.currTurnStatus != eTurnStatus.my) { return; } if (GameManager.instance.currGameMode == eGameMode.vCPU && GameManager.instance.currTurnStatus != eTurnStatus.my) { return; } BordManager.instace.OnInputByUser(pData); if (GameManager.instance.currGameMode == eGameMode.vServerMulltiPlayer) { Debug.Log("Input By User " + pData); tokenID++; InputPacket ip = new InputPacket(tokenID, pData); myCurrTurnInput.Enqueue(ip); //ConnectionManager.Instance.OnSendMeAnswer (pData+""); StartCoroutine("WaitAndSendData"); } }
void Update() { InputPacket ip = new InputPacket(); if (IsCurrentPlayer) { ip = playerMovement(); } else { ip = npcMovement(); } baseMovement(ip); foreach (OffensiveTemplate ot in m_offensiveTemplates) { ot.HandleInput(ip); } #region powers if (poweredUp) { powerUpCooldown -= Time.deltaTime; if (powerUpCooldown <= 0) { poweredUp = false; doubleJumpAvailable = false; canDoubleJump = false; FindObjectOfType <PowerUpUI>().DestroyJump(); } } #endregion }
public override void HandleInput(InputPacket ip) { if (ip.leftMousePress) { m_charBase.TryAction(OnLeftMouse, null, InputKey.Fire); m_charBase.TryAction(OnLeftMouseName, null, InputKey.Fire); } if (ip.rightMousePress) { m_charBase.TryAction(OnRightMouse, null, InputKey.Fire2); m_charBase.TryAction(OnRightMouseName, null, InputKey.Fire); } if (ip.InputKeyPressed.ContainsKey(InputKey.Interact) && ip.InputKeyPressed[InputKey.Interact]) { m_charBase.TryAction(OnInteractButton, null, InputKey.Interact); m_charBase.TryAction(OnInteractName, null, InputKey.Interact); } foreach (InputKey keyID in ButtonActions.Keys) { if (ip.InputKeyPressed.ContainsKey(keyID) && ip.InputKeyPressed[keyID]) { m_charBase.TryAction(ButtonActions[keyID]); } } foreach (InputKey keyID in ButtonActionStrings.Keys) { if (ip.InputKeyPressed.ContainsKey(keyID) && ip.InputKeyPressed[keyID]) { m_charBase.TryAction(ButtonActions[keyID]); } } }
// Update is called once per frame public override InputPacket AITemplate() { InputPacket ip = new InputPacket(); m_agent.updateRotation = false; m_agent.nextPosition = transform.position; if (Input.GetMouseButtonDown(0)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { m_agent.SetDestination(hit.point); } } m_agent.updatePosition = false; m_agent.updateRotation = false; Vector2 target = new Vector2(m_agent.destination.x, m_agent.destination.z); Vector2 me = new Vector2(transform.position.x, transform.position.z); if (Vector2.Distance(me, target) > m_tolerance) { ip.movementInput = m_agent.desiredVelocity.normalized; //m_agent.velocity = m_charControl.velocity; } else { ip.movementInput = Vector3.zero; } return(ip); }
private void currentPlayerControl(InputPacket ip) { if (ip.InputMove.magnitude > 0.01f) { Direction d = m_orient.VectorToDirection(ip.InputMove); m_orient.SetDirection(d); } m_jumpDown = ip.JumpDown; m_jumpHold = ip.JumpHold; if (CanJump) { JumpMovement(); } if (m_eqp != null) { if (ip.equipmentSlotUsed != "None") { m_eqp.EquipmentUseUpdatePlayer(ip.equipmentSlotUsed, ip.InputMove); } } if (ip.OpenInventory) { m_eqp.ToggleDisplay(); } if (ip.Interact) { m_eqp.CloseContainer(); GetComponent <Interactor>().OnAttemptInteract(); } m_inputMove = ip.InputMove; m_currentlySprinting = ip.Sprint; }
public override void HandleInput(InputPacket ip) { if (Weapon == null) { return; } if (Weapon.auto) { if (ip.fire1) { if (coolDown <= 0) { fire(Weapon, ip.MousePointWorld); } } } else { if (ip.fire1Press) { if (coolDown <= 0) { fire(Weapon, ip.MousePointWorld); } } } if (coolDown >= 0) { coolDown -= 1 * Time.deltaTime; } }
public override InputPacket AITemplate() { InputPacket ip = new InputPacket(); float t = Time.timeSinceLevelLoad; if (m_targetObj != null) { float d = Vector2.Distance(m_targetObj.transform.position, transform.position); if (d < StartShootingRange) { Vector2 target = new Vector2(m_targetObj.transform.position.x + TargetOffset.x, m_targetObj.transform.position.y + TargetOffset.y); target += new Vector2(Random.Range(RandomRangeX.x, RandomRangeX.y), Random.Range(RandomRangeY.x, RandomRangeY.y)); target.x = target.x - transform.position.x; target.y = target.y - transform.position.y; ip.MousePointWorld = target; if (t < m_fireHoldTime) { ip.fire1 = true; } if (ShootProbability > 0.0f && t > m_nextShootTime) { if (Random.Range(0, 100) < ShootProbability) { m_nextShootTime = t + ShootCheckInterval; ip.fire1Press = true; m_fireHoldTime = t + ShootHoldBurstTime; } } } } return(ip); }
// Update is called once per frame void FixedUpdate() { ip = inputSource.GetInputPacket(); desireRot += curRot * Time.fixedDeltaTime; m_body.transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, desireRot)); UpdateSpeed(ip); }
private void currentPlayerControl(InputPacket ip) { if (ip.movementInput.magnitude > 0.01f && m_orient != null) { m_orient.FaceVector(ip.movementInput); //m_orient.SetDirection(d); } if (ip.leftMouse || ip.leftMousePress || ip.rightMouse || ip.rightMousePress || ip.middleMouse || ip.middleMousePress) { m_orient.FacePoint(ip.MousePointWorld); } m_jumpDown = ip.jumpDown; m_jumpHold = ip.jump; if (CanJump) { JumpMovement(); } //if (ip.inventory) //{ // m_eqp.ToggleDisplay(); //} //if (ip.interact) { // m_eqp.CloseContainer(); // //GetComponent<Interactor>().OnAttemptInteract(); //} m_inputMove = ip.movementInput; }
public override void HandleInput(InputPacket ip) { if (ip.InputKeyPressed.ContainsKey(InputKey.Inventory) && ip.InputKeyPressed[InputKey.Inventory] && (!RequirePlayerControllable || GetComponent <MovementBase>().IsPlayerControl)) { GetComponent <InventoryHolder>().ToggleAllInventory(); } }
public void Combine(InputPacket ip) { movementInput = movementInput + ip.movementInput; MousePointWorld = ip.MousePointWorld; jump = jump || ip.jump; fire1 = fire1 || ip.fire1; fire1Press = fire1Press || ip.fire1Press; }
// Start is called before the first frame update void Start() { target = FindObjectOfType <PlayerInputBody>().gameObject; mRigidBody = GetComponent <Rigidbody2D>(); mTransform = this.transform; targetTransform = target.transform; ip = new InputPacket(); }
private void processExtraMovement() { if (m_extraInputs != null) { m_eqp.EquipmentUseUpdatePlayer(m_extraInputs.equipmentSlotUsed, m_extraInputs.InputMove); m_extraInputs = null; } }
public void Combine(InputPacket ip) { movementInput = movementInput + ip.movementInput; MousePointWorld = ip.MousePointWorld; jump = jump || ip.jump; leftMouse = leftMouse || ip.leftMouse; leftMousePress = leftMousePress || ip.leftMousePress; }
public override InputPacket AITemplate() { InputPacket ip = new InputPacket(); m_agent.updateRotation = false; if (m_isFollow) { if (m_followTarget != null) { m_agent.SetDestination(m_followTarget.transform.position); } else { m_isFollow = false; } } m_agent.updatePosition = false; m_agent.updateRotation = false; Vector3 d = m_targetPoint - transform.position; float dist = Vector3.Magnitude(new Vector3(d.x, 0f, d.z)); if (dist > m_tolerance) { ip.movementInput = m_agent.desiredVelocity.normalized; //m_agent.velocity = m_charControl.velocity; Destination = m_agent.destination; } float t = Time.timeSinceLevelLoad; if (t < primaryHoldUntil || primaryPressed) { ip.leftMouse = true; ip.movementInput += UseItemInput; } if (t < secondaryHoldUntil || secondaryPressed) { ip.rightMouse = true; ip.movementInput += UseItemInput; } if (primaryPressed) { ip.leftMousePress = true; primaryPressed = false; } if (secondaryPressed) { ip.rightMousePress = true; secondaryPressed = false; } if (slotUse.Count > 0) { ip.itemSlotUse.AddRange(slotUse); slotUse.Clear(); } return(ip); }
protected override void OnUpdate() { if (Input.GetKeyDown(KeyCode.KeypadPlus)) { Sensivity++; } if (Input.GetKeyDown(KeyCode.KeypadMinus)) { Sensivity--; } if (Input.GetKeyDown(KeyCode.KeypadMultiply)) { Sensivity = 3f; } var currentInput = m_InputClient.CurrentInput; for (int i = 0; i != m_NetworkGroup.Length; i++) { var netEntity = m_NetworkGroup.NetworkEntities[i]; InputPacket packet; if (GameServerManagement.IsCurrentlyHosting) { packet = new InputPacket(netEntity.ToEntity(), m_NetworkGroup.Inputs[i].Aim); SendNewInputToClients(netEntity.GetNetworkInstance(), packet); } else { if (!m_NetworkGroup.Entities[i].HasComponent <ClientDriveData <DefStEntityAimInput> >()) { continue; } packet = new InputPacket(netEntity.ToEntity(), GetNewRotation(currentInput, m_NetworkGroup.ClientInputs[i].Aim)); SendNewInputToServer(netEntity, packet); SetClientInput(m_NetworkGroup.Entities[i], new DefStEntityAimClientInput(packet.Aim)); } } for (int i = 0; i != m_LocalGroup.Length; i++) { if (!m_LocalGroup.Entities[i].HasComponent <ClientDriveData <DefStEntityAimInput> >()) { continue; } var newRotation = GetNewRotation(currentInput, m_LocalGroup.ClientInputs[i].Aim); EntityUpdateInput(m_LocalGroup.Entities[i], new DefStEntityAimInput(newRotation), false); SetClientInput(m_LocalGroup.Entities[i], new DefStEntityAimClientInput(newRotation)); } m_InputClient.ToZero(); }
private void CmdSendInput(sbyte horizontal, sbyte vertical) { InputPacket packet = new InputPacket(horizontal, vertical); if (playerController != null && !RoundManager.Instance.stopPlayerInput) { playerController.ApplyMovement(packet); } }
public void UseItem(string slot, Vector2 direction) { if (m_extraInputs == null) { m_extraInputs = new InputPacket(); } m_extraInputs.equipmentSlotUsed = slot; m_extraInputs.InputMove = direction; }
private void SendNewInputToClients(NetworkInstance caller, InputPacket packet) { var msgMgr = caller.GetMessageManager(); var msgData = msgMgr.Create(InputMsgToClientsId); packet.WriteTo(msgData); m_NetworkMessageSystem.InstantSendToAllDefault(caller, msgData, DeliveryMethod.Unreliable); }
private void SendNewInputToServer(NetworkEntity entity, InputPacket packet) { var msgMgr = GameServerManagement.Main.LocalInstance.GetMessageManager(); var msgData = msgMgr.Create(InputMsgToServerId); packet.WriteTo(msgData); m_NetworkMessageSystem.InstantSendToAllDefault(entity.GetNetworkInstance(), msgData, DeliveryMethod.Unreliable); }
internal InputPacket npcMovement() { InputPacket ip = new InputPacket(); foreach (AIInputParentClass aib in m_aibase) { ip.Combine(aib.AITemplate()); } return(ip); }
// Update is called once per frame void FixedUpdate() { ip = input.GetInputPacket(ip); ChangeTranslate(ip); ChangeRotate(ip); xvel = (Mathf.Rad2Deg * Time.fixedDeltaTime * Mathf.Cos(rgd.rotation * Mathf.Deg2Rad)) * moveSpeed; yvel = (Mathf.Rad2Deg * Time.fixedDeltaTime * Mathf.Sin(rgd.rotation * Mathf.Deg2Rad)) * moveSpeed; rgd.velocity = new Vector2(xvel, yvel); rgd.angularVelocity = rotSpeed; }
// Update is called once per frame void Update() { InputPacket p = new InputPacket(); if (m_aibase != null) { p = m_aibase.AITemplate(); } MovePlayer(p); }
protected override void OnConclude() { base.OnConclude(); InputPacket ip = getLastInputPacket(); if (m_weaponStats.auto && ip.InputKeyPressed.ContainsKey(m_useButton)) { ResetAndProgress(); } }
// Start is called before the first frame update void Start() { m_body = GetComponent <Transform>(); gs = GetComponent <GunStats>(); maxRotSpeed = gs.maxRotSpeed; accelRotSpeed = gs.accelRotSpeed; slowRotSpeed = gs.dampenRotSpeed; ip = new InputPacket(); //if (playerControl) //playerInput = GetComponent<PlayerInputTurret>(); }