Esempio n. 1
0
        /// <summary>
        /// Remove an entity from being controlled by this peer.
        /// </summary>
        public void RevokeControl(ServerEntity entity)
        {
            Debug.Assert(entity.Controller == this);
            ControlledEntities.Remove(entity);

            entity.Controller = null;
            entity.IncomingCommands.Clear();
            entity.DeferNotifyControllerChanged = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Adds an entity to be controlled by this peer.
        /// </summary>
        public void GrantControl(ServerEntity entity)
        {
            if (entity.Controller != this)
            {
                Debug.Assert(entity.Controller == null);
                ControlledEntities.Add(entity);

                entity.Controller = this;
                entity.IncomingCommands.Clear();
                entity.DeferNotifyControllerChanged = true;
            }
        }
Esempio n. 3
0
        public bool ChangedSinceStart()
        {
            if (ControlledEntities.Empty())
            {
                return(false);
            }

            // Take the first entity as starting point
            var transform = ControlledEntity.Transform;

            return((transform.Position - StartingTransforms[0].Position).Length() > Constants.Epsilon ||
                   (transform.Rotation.ToFloat3() - StartingTransforms[0].Rotation.ToFloat3()).Length() > Constants.Epsilon ||
                   (transform.Scale - StartingTransforms[0].Scale).Length() > Constants.Epsilon);
        }
Esempio n. 4
0
        public void EndEdit()
        {
            if (ControlledEntities.Count == 0 || StartingTransforms.Count == 0)
            {
                return;
            }

            if (ControlledEntities.Count > 1)
            {
                Editor.AddUndoAction(new UndoGroupTransformAction(ControlledEntities.Select(x => x.EntityId).ToArray(), StartingTransforms.ToArray()));
            }
            else
            {
                Editor.AddUndoAction(new UndoTransformAction(ControlledEntities[0].EntityId, StartingTransforms[0]));
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked             // Overflow is fine, just wrap
            {
                int hashCode = 41;
                // Suitable nullity checks etc, of course :)

                hashCode = hashCode * 59 + Id.GetHashCode();
                if (ControlledEntities != null)
                {
                    hashCode = hashCode * 59 + ControlledEntities.GetHashCode();
                }

                hashCode = hashCode * 59 + OnTurn.GetHashCode();

                hashCode = hashCode * 59 + Active.GetHashCode();
                if (DisplayName != null)
                {
                    hashCode = hashCode * 59 + DisplayName.GetHashCode();
                }
                return(hashCode);
            }
        }
Esempio n. 6
0
        /// <summary>
        ///     Returns true if Player instances are equal
        /// </summary>
        /// <param name="other">Instance of Player to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Player other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id.Equals(other.Id)
                     ) &&
                 (
                     ControlledEntities == other.ControlledEntities ||
                     ControlledEntities != null &&
                     other.ControlledEntities != null &&
                     ControlledEntities.SequenceEqual(other.ControlledEntities)
                 ) &&
                 (
                     OnTurn == other.OnTurn ||
                     OnTurn.Equals(other.OnTurn)
                 ) &&
                 (
                     Active == other.Active ||
                     Active.Equals(other.Active)
                 ) &&
                 (
                     DisplayName == other.DisplayName ||
                     DisplayName != null &&
                     DisplayName.Equals(other.DisplayName)
                 ));
        }