示例#1
0
            internal override Model ReadEntry(BinaryReaderEx br)
            {
                var model = new Model(br);

                switch (model.Type)
                {
                case ModelType.MapPiece:
                    MapPieces.Add(model);
                    return(model);

                case ModelType.Object:
                    Objects.Add(model);
                    return(model);

                case ModelType.Collision:
                    Collisions.Add(model);
                    return(model);

                case ModelType.Navmesh:
                    Navmeshes.Add(model);
                    return(model);

                default:
                    throw new NotImplementedException($"Unimplemented model type: {model.Type}");
                }
            }
示例#2
0
            /// <summary>
            /// Adds a part to the appropriate list for its type; returns the part.
            /// </summary>
            public Part Add(Part part)
            {
                switch (part)
                {
                case Part.MapPiece p: MapPieces.Add(p); break;

                case Part.Object p: Objects.Add(p); break;

                case Part.Enemy p: Enemies.Add(p); break;

                case Part.Player p: Players.Add(p); break;

                case Part.Collision p: Collisions.Add(p); break;

                case Part.Protoboss p: Protobosses.Add(p); break;

                case Part.Navmesh p: Navmeshes.Add(p); break;

                case Part.DummyObject p: DummyObjects.Add(p); break;

                case Part.DummyEnemy p: DummyEnemies.Add(p); break;

                case Part.ConnectCollision p: ConnectCollisions.Add(p); break;

                default:
                    throw new ArgumentException($"Unrecognized type {part.GetType()}.", nameof(part));
                }
                return(part);
            }
示例#3
0
            /// <summary>
            /// Adds a model to the appropriate list for its type; returns the model.
            /// </summary>
            public Model Add(Model model)
            {
                switch (model)
                {
                case Model.MapPiece m: MapPieces.Add(m); break;

                case Model.Object m: Objects.Add(m); break;

                case Model.Enemy m: Enemies.Add(m); break;

                case Model.Item m: Items.Add(m); break;

                case Model.Player m: Players.Add(m); break;

                case Model.Collision m: Collisions.Add(m); break;

                case Model.Navmesh m: Navmeshes.Add(m); break;

                case Model.Other m: Others.Add(m); break;

                default:
                    throw new ArgumentException($"Unrecognized type {model.GetType()}.", nameof(model));
                }
                return(model);
            }
示例#4
0
            public void Add(IMsbModel item)
            {
                var m = (Model)item;

                switch (m.Type)
                {
                case ModelType.MapPiece:
                    MapPieces.Add(m);
                    break;

                case ModelType.Object:
                    Objects.Add(m);
                    break;

                case ModelType.Collision:
                    Collisions.Add(m);
                    break;

                case ModelType.Navmesh:
                    Navmeshes.Add(m);
                    break;

                default:
                    throw new ArgumentException(
                              message: "Item is not recognized",
                              paramName: nameof(item));
                }
            }
            internal override Part ReadEntry(BinaryReaderEx br)
            {
                PartType type = br.GetEnum16 <PartType>(br.Position + 8);

                switch (type)
                {
                case PartType.MapPiece:
                    var mapPiece = new Part.MapPiece(br);
                    MapPieces.Add(mapPiece);
                    return(mapPiece);

                case PartType.Object:
                    var obj = new Part.Object(br);
                    Objects.Add(obj);
                    return(obj);

                case PartType.Collision:
                    var collision = new Part.Collision(br);
                    Collisions.Add(collision);
                    return(collision);

                case PartType.Navmesh:
                    var navmesh = new Part.Navmesh(br);
                    Navmeshes.Add(navmesh);
                    return(navmesh);

                case PartType.ConnectCollision:
                    var connectCollision = new Part.ConnectCollision(br);
                    ConnectCollisions.Add(connectCollision);
                    return(connectCollision);

                default:
                    throw new NotImplementedException($"Unimplemented part type: {type}");
                }
            }
            public void Add(IMsbPart item)
            {
                switch (item)
                {
                case Part.MapPiece m:
                    MapPieces.Add(m);
                    break;

                case Part.Object m:
                    Objects.Add(m);
                    break;

                case Part.Collision m:
                    Collisions.Add(m);
                    break;

                case Part.Navmesh m:
                    Navmeshes.Add(m);
                    break;

                case Part.ConnectCollision m:
                    ConnectCollisions.Add(m);
                    break;

                default:
                    throw new ArgumentException(
                              message: "Item is not recognized",
                              paramName: nameof(item));
                }
            }
示例#7
0
            internal override Model ReadEntry(BinaryReaderEx br)
            {
                ModelType type  = br.GetEnum32 <ModelType>(br.Position + 4);
                var       model = new Model(br);

                if (type == ModelType.MapPiece)
                {
                    MapPieces.Add(model);
                }
                else if (type == ModelType.Object)
                {
                    Objects.Add(model);
                }
                else if (type == ModelType.Enemy)
                {
                    Enemies.Add(model);
                }
                else if (type == ModelType.Player)
                {
                    Players.Add(model);
                }
                else if (type == ModelType.Collision)
                {
                    Collisions.Add(model);
                }
                else if (type == ModelType.Navmesh)
                {
                    Navmeshes.Add(model);
                }
                else
                {
                    throw new NotImplementedException($"Unimplemented model type: {type}");
                }
                return(model);
            }
示例#8
0
 protected void OnCollisionEnter(Collision collision)
 {
     audioSource.PlayOneShot(FallSound);
     if (!Collisions.ContainsKey(collision.collider))
     {
         Collisions.Add(collision.collider, collision);
     }
 }
示例#9
0
            internal override Part ReadEntry(BinaryReaderEx br)
            {
                PartType type = br.GetEnum32 <PartType>(br.Position + 4);

                switch (type)
                {
                case PartType.MapPiece:
                    var mapPiece = new Part.MapPiece(br);
                    MapPieces.Add(mapPiece);
                    return(mapPiece);

                case PartType.Object:
                    var obj = new Part.Object(br);
                    Objects.Add(obj);
                    return(obj);

                case PartType.Enemy:
                    var enemy = new Part.Enemy(br);
                    Enemies.Add(enemy);
                    return(enemy);

                case PartType.Player:
                    var player = new Part.Player(br);
                    Players.Add(player);
                    return(player);

                case PartType.Collision:
                    var collision = new Part.Collision(br);
                    Collisions.Add(collision);
                    return(collision);

                case PartType.Navmesh:
                    var navmesh = new Part.Navmesh(br);
                    Navmeshes.Add(navmesh);
                    return(navmesh);

                case PartType.DummyObject:
                    var dummyObject = new Part.DummyObject(br);
                    DummyObjects.Add(dummyObject);
                    return(dummyObject);

                case PartType.DummyEnemy:
                    var dummyEnemy = new Part.DummyEnemy(br);
                    DummyEnemies.Add(dummyEnemy);
                    return(dummyEnemy);

                case PartType.ConnectCollision:
                    var connectCollision = new Part.ConnectCollision(br);
                    ConnectCollisions.Add(connectCollision);
                    return(connectCollision);

                default:
                    throw new NotImplementedException($"Unimplemented part type: {type}");
                }
            }
        internal void Read(ParameterTree tree)
        {
            if (tree.OpenScope("root"))
            {
                Force                = tree.Get <float>("force");
                ForceGain            = tree.Get <float>("force_gain");
                AirResistance        = tree.Get <float>("air_res");
                RotationY            = tree.Get <float>("rot_y");
                RotationZ            = tree.Get <float>("rot_z");
                Friction             = tree.Get <float>("friction");
                WindAffection        = tree.Get <float>("wind_afc");
                CollisionType        = tree.Get <uint>("coli_type");
                InitRotationY        = tree.Get <float>("init_rot_y");
                InitRotationZ        = tree.Get <float>("init_rot_z");
                HingeY               = tree.Get <float>("hinge_y", 90);
                HingeZ               = tree.Get <float>("hinge_z", 90);
                CollisionRadius      = tree.Get <float>("coli_r");
                Stiffness            = tree.Get <float>("stiffness");
                MoveCancel           = tree.Get <float>("move_cancel");
                CollisionTargetOsage = tree.Get <string>("colli_tgt_osg");

                tree.Enumerate("coli", i =>
                {
                    var collision = new OsageCollisionParameter();
                    collision.Read(tree);
                    Collisions.Add(collision);
                });

                tree.Enumerate("boc", i =>
                {
                    var boc = new OsageBocParameter();
                    boc.Read(tree);
                    Bocs.Add(boc);
                });

                tree.CloseScope();
            }

            tree.Enumerate("node", i =>
            {
                var node = new OsageNodeParameter();
                node.Read(tree);
                Nodes.Add(node);
            });
        }
示例#11
0
        /// <summary>
        /// Get a set of Collisions with a given kind of GameObejct
        /// </summary>
        /// <typeparam name="G">Some type of GameObject</typeparam>
        /// <returns>A set of Collisions</returns>
        public Collisions <G> currentCollisions <G>() where G : GameObject
        {
            Collisions <G> collList = new Collisions <G>();
            List <G>       all      = objectManager.getAllObjectsOfType <G>();

            all.ForEach((gob) =>
            {
                if (gob != this)
                {
                    CollisionInfo info = gob.Bounds.getCollisionInfo(Bounds);
                    if (info != null)
                    {
                        collList.Add(new Collision <G>(info, gob));
                    }
                }
            });
            return(collList);
        }
        public void Copy(CollisionObject _object)
        {
            if (_object == null)
            {
                return;
            }

            base.Copy(_object);


            UseCollider            = _object.UseCollider;
            UseTrigger             = _object.UseTrigger;
            UseCharacterController = _object.UseCharacterController;
            AllowChildCollisions   = _object.AllowChildCollisions;

            Collisions.Clear();
            foreach (CollisionDataObject _data in _object.Collisions)
            {
                Collisions.Add(new CollisionDataObject(_data));
            }
        }
        internal void Read(EndianBinaryReader reader)
        {
            Force         = reader.ReadSingle();
            ForceGain     = reader.ReadSingle();
            AirResistance = reader.ReadSingle();

            if (reader.AddressSpace == AddressSpace.Int64)
            {
                reader.SkipNulls(4);
            }

            RotationY     = reader.ReadSingle();
            RotationZ     = reader.ReadSingle();
            InitRotationY = reader.ReadSingle();
            InitRotationZ = reader.ReadSingle();
            HingeY        = reader.ReadSingle();
            HingeZ        = reader.ReadSingle();
            Name          = reader.ReadStringOffset(StringBinaryFormat.NullTerminated);

            for (int i = 0; i < 12; i++)
            {
                var collision = new OsageCollisionParameter();
                collision.Read(reader);

                if (!string.IsNullOrEmpty(collision.Bone0.Name) && !string.IsNullOrEmpty(collision.Bone1.Name))
                {
                    Collisions.Add(collision);
                }
            }

            reader.SkipNulls(4);   // padding?

            Friction      = reader.ReadSingle();
            WindAffection = reader.ReadSingle();

            reader.SkipNulls(4);   // padding?

            int bocCount, nodeCount;

            // X
            if (reader.AddressSpace == AddressSpace.Int64)
            {
                bocCount      = reader.ReadInt32();
                CollisionType = reader.ReadUInt32();
                reader.ReadOffset(ReadBocs);

                nodeCount = reader.ReadInt32();

                reader.SkipNulls(8);

                // Murmur hash of name
                reader.SeekCurrent(sizeof(ulong));

                reader.ReadOffset(ReadNodes);
            }

            // F 2nd
            else
            {
                bocCount = reader.ReadInt32();
                reader.ReadOffset(ReadBocs);
                CollisionType = reader.ReadUInt32();

                reader.SkipNulls(4);

                // Murmur hash of name
                reader.SeekCurrent(sizeof(ulong));

                nodeCount = reader.ReadInt32();
                reader.ReadOffset(ReadNodes);
            }

            void ReadBocs()
            {
                Bocs.Capacity = bocCount;

                for (int i = 0; i < bocCount; i++)
                {
                    var boc = new OsageBocParameter();
                    boc.Read(reader);
                    Bocs.Add(boc);
                }
            }

            void ReadNodes()
            {
                Nodes.Capacity = nodeCount;

                for (int i = 0; i < nodeCount; i++)
                {
                    var node = new OsageNodeParameter();
                    node.Read(reader);
                    Nodes.Add(node);
                }
            }
        }
示例#14
0
        private void ReadPrimitiveSection(XElement element)
        {
            switch (element.Name.LocalName)
            {
            case SECTION_ANNOTATIONS:

                foreach (var annotationElem in element.Elements("Annotation"))
                {
                    try { ReadAnnotation(annotationElem); }
                    catch { }
                }
                break;

            case SECTION_COLLISION:
                foreach (var colElem in element.Elements())
                {
                    Collisions.Add(Collision.DeserializeCollision(colElem));
                }
                break;

            case SECTION_CONNECTIVITY:
                foreach (var conElem in element.Elements())
                {
                    Connectors.Add(Connector.DeserializeConnector(conElem));
                }
                break;

            case SECTION_PHYSICSATTRIBUTES:
                PhysicsAttributes = XmlHelper.DefaultDeserialize <PhysicsAttributes>(element);
                break;

            case "Bounding":
                Bounding = new BoundingBox();
                Bounding.LoadFromXml(element.Element("AABB"));

                break;

            case "GeometryBounding":
                GeometryBounding = new BoundingBox();
                GeometryBounding.LoadFromXml(element.Element("AABB"));
                break;

            case "Decoration":

                if (FileVersion.Major == 1 && element.HasAttribute("faces"))
                {
                    try
                    {
                        int surfaceCount = element.ReadAttribute <int>("faces");
                        SubMaterials = new int[surfaceCount];
                        var values = element.ReadAttribute <string>("subMaterialRedirectLookupTable").Split(',');
                        for (int i = 0; i < surfaceCount; i++)
                        {
                            SubMaterials[i] = int.Parse(values[i]);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("invalid primitive version");
                    }
                }

                break;

            case "Flex":
                foreach (var boneElement in element.Elements())
                {
                    FlexBones.Add(XmlHelper.DefaultDeserialize <FlexBone>(boneElement));
                }
                break;

            case "DefaultOrientation":
                DefaultOrientation = Transform.FromElementAttributes(element);
                break;

            case "DefaultCamera":
                DefaultCamera = XmlHelper.DefaultDeserialize <Camera>(element);
                break;

            //case "Paths":
            //    break;

            default:
                //if (ExtraElements == null)
                //    ExtraElements = new List<XElement>();
                var clonedElem = XElement.Parse(element.ToString());
                ExtraElements.Add(clonedElem);
                break;
            }
        }
        private void OnTriggerEnter(Collider other)
        {
            //If the object has already been hit or if the collider is multihit return
            if (Collisions.Contains(other.gameObject) || IsMultiHit)
            {
                return;
            }

            ColliderBehaviour otherCollider = null;

            if (other.attachedRigidbody)
            {
                if (other.attachedRigidbody.gameObject != Owner)
                {
                    otherCollider = other.attachedRigidbody.gameObject.GetComponentInChildren <ColliderBehaviour>();
                }
                else
                {
                    return;
                }
            }

            if (other.CompareTag("ParryBox"))
            {
                return;
            }

            if (otherCollider && !other.CompareTag("Player") && !other.CompareTag("Entity"))
            {
                if (IgnoreColliders || otherCollider.IgnoreColliders || otherCollider.ColliderOwner == Owner)
                {
                    return;
                }
                else if (otherCollider is HitColliderBehaviour)
                {
                    if (((HitColliderBehaviour)otherCollider).Priority >= Priority && otherCollider.ColliderOwner != ColliderOwner)
                    {
                        Destroy(gameObject);
                        return;
                    }

                    return;
                }
            }

            float newHitAngle = _hitAngle;

            //Calculates new angle if this object should change trajectory based on direction of hit
            if (_adjustAngleBasedOnCollision)
            {
                //Find a vector that point from the collider to the object hit
                Vector3 directionOfImpact = other.transform.position - transform.position;
                directionOfImpact.Normalize();
                directionOfImpact.x = Mathf.Round(directionOfImpact.x);

                //Find the direction this collider was going to apply force originally
                Vector3 currentForceDirection = new Vector3(Mathf.Cos(newHitAngle), Mathf.Sin(newHitAngle), 0);
                currentForceDirection.x *= directionOfImpact.x;

                //Find the new angle based on the direction of the attack on the x axis
                float dotProduct = Vector3.Dot(currentForceDirection, Vector3.right);
                newHitAngle = Mathf.Acos(dotProduct);

                //Find if the angle should be negative or positive
                if (Vector3.Dot(currentForceDirection, Vector3.up) < 0)
                {
                    newHitAngle *= -1;
                }
            }

            //Add the game object to the list of collisions so it is not collided with again
            Collisions.Add(other.gameObject);

            //Grab whatever health script is attached to this object
            HealthBehaviour damageScript = other.GetComponent <HealthBehaviour>();

            if (Owner)
            {
                OwnerName = Owner.name;
            }

            //If the damage script wasn't null damage the object
            if (damageScript != null)
            {
                damageScript.TakeDamage(OwnerName, _damage, _knockBackScale, newHitAngle, damageType, _hitStunTime);
            }

            onHit?.Invoke(other.gameObject, otherCollider);

            if (DestroyOnHit)
            {
                Destroy(gameObject);
            }
        }