These are chat archives for ikkentim/SampSharp

19th
Sep 2016
Tim Potze
@ikkentim
Sep 19 2016 06:50
Oh, make sure you use the pre-release library, in nuget, check the “allow unstable” checkbox or something like that
Florian van Dillen
@fvandillen
Sep 19 2016 07:06
NuGet did say 7. Something
Will try now and let you know
Tim Potze
@ikkentim
Sep 19 2016 07:16
If it doesn’t work, I’ll check after work
Florian van Dillen
@fvandillen
Sep 19 2016 07:30
Yup, it worked
Somehow it said 7.x, but installed 6.x
Tim Potze
@ikkentim
Sep 19 2016 07:56
:)
Tim Potze
@ikkentim
Sep 19 2016 19:03
Now working on a testing framework :)
Something to mock all native instances
Florian van Dillen
@fvandillen
Sep 19 2016 19:12
While you do that, I have a question
I have a Player class which functions as my pooled type BasePlayer
The Player class contains a property called Account which contains username, password, etc
The Account class is mapped to the database
What would the best way be to compare one player instance with another based on their account?
Tim Potze
@ikkentim
Sep 19 2016 19:13
To see if two have logged in with the same account?
p1.Account.Id == p2.Account.Id? I'm not quite sure yet how you want to compare them.
Florian van Dillen
@fvandillen
Sep 19 2016 19:15
well yes, I want to be able to distinguish one instance from another (or make sure they are equal)
And yes, right now I am doing p.Account.Id
while I would love to be able to do if( p1 == p2 )
or if( p1.Account == p2.Account)
Tim Potze
@ikkentim
Sep 19 2016 19:16
Theoretically , a good orm would not create new instances for both Accounts, so p.Account = p2.Account would work
Florian van Dillen
@fvandillen
Sep 19 2016 19:16
I'll try to show a good use case of what I want to do
Tim Potze
@ikkentim
Sep 19 2016 19:16
in every other case, go and overload the == operator and override the Equals Method
(in the Account class)
```
Florian van Dillen
@fvandillen
Sep 19 2016 19:17
Overloading .Equals sounds fine
And how do you overload ==?
Tim Potze
@ikkentim
Sep 19 2016 19:18

        protected bool Equals(FakePlayerDefinition other)
        {
            return id == other.id;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != this.GetType()) return false;
            return Equals((FakePlayerDefinition) obj);
        }

        public override int GetHashCode()
        {
            return id;
        }

        public static bool operator ==(FakePlayerDefinition left, FakePlayerDefinition right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(FakePlayerDefinition left, FakePlayerDefinition right)
        {
            return !Equals(left, right);
        }
(dont mind the fake player definition, just picked a random class in my current project:P )
Florian van Dillen
@fvandillen
Sep 19 2016 19:19
brilliant
See exactly what you did there
and that was exactly what I meant
Tim Potze
@ikkentim
Sep 19 2016 19:20
(code courtesy of Resharper :P )
code generators, hmmm so nice
Florian van Dillen
@fvandillen
Sep 19 2016 19:20
In which class did you define those methods?
I would prefer to define them in the class they belong to
Tim Potze
@ikkentim
Sep 19 2016 19:21
In the class you are comparing
so Account in your case
and replace FakePlayerDefinition with Account
Florian van Dillen
@fvandillen
Sep 19 2016 19:21
(Just trying to gain an understanding here :P )
Sweet, will go ahead and play with this
Tim Potze
@ikkentim
Sep 19 2016 19:22
Check our some operator overloading info on google: basically you can overload any operator ( ==, +, /, etc) or implicit/explicit cast by putting some code in either class it involves
Florian van Dillen
@fvandillen
Sep 19 2016 19:22
Didnt even know that was possible
Well overloading I did, but not operators
absolutely brilliant
Tim Potze
@ikkentim
Sep 19 2016 19:23
class Foo{}
class Bar
{
  public static bool operator ==(Foo f, Bar b)
  {
    // logic
  }
}
class Foo{}
class Bar
{
  public static implicit operator Bar(Foo f)
  {
    // logic
    return new Bar();
  }
}
now you can do Bar x = new Foo();
Tim Potze
@ikkentim
Sep 19 2016 19:48
Yay!
        [TestMethod]
        public void TestSomething()
        {
            // Setup
            var srv = ServerImitator.Boot<TestGameMode>();

            // Connect
            var playerid = srv.ConnectPlayer("John Doe", "127.0.0.1");

            // Check name
            var args = new object[2];
            args[0] = playerid;

            Native.Load("GetPlayerName", typeof(int), typeof(string).MakeByRefType()).Invoke(args);

            // Assert
            Assert.AreEqual("John Doe", args[1]);
        }
Florian van Dillen
@fvandillen
Sep 19 2016 19:48
Oh sheet
Mocking the crap out of the server
Tim Potze
@ikkentim
Sep 19 2016 19:48
Yea :P
Florian van Dillen
@fvandillen
Sep 19 2016 19:48
I am working on a sick item system
Tim Potze
@ikkentim
Sep 19 2016 19:48
Working my way trough all posible native logic
Florian van Dillen
@fvandillen
Sep 19 2016 19:49
With inventories, dropping items in the game world
Tim Potze
@ikkentim
Sep 19 2016 19:49
Nice !
I worked on an inventory system too, once upon a time when i was working on my gamemode instead of my gamemode framework :P
I just had shops, different inventory types (cars, houses, person, shops)
Florian van Dillen
@fvandillen
Sep 19 2016 19:50
Oh nice
(definitions)
Florian van Dillen
@fvandillen
Sep 19 2016 19:50
Also worked on a nice textdraw-driven notification system a-la toast
Tim Potze
@ikkentim
Sep 19 2016 19:50
:) nice those are basics you need
Tim Potze
@ikkentim
Sep 19 2016 19:51
When I'm done with this, I want to create SampSharp.UI with UI utils
Florian van Dillen
@fvandillen
Sep 19 2016 19:51
Oh nice
Tim Potze
@ikkentim
Sep 19 2016 19:51
Terminal? booh! download iTerm!
Florian van Dillen
@fvandillen
Sep 19 2016 19:51
I initialize the notification controller for every player
It's iterm man :)
Tim Potze
@ikkentim
Sep 19 2016 19:51
Hmm I should hide the icon less
my build configuration is awesome now btw :)
You see how I stack notification elements in a list
then cycle through them with a timer
Tim Potze
@ikkentim
Sep 19 2016 19:53
That's the right way :)
Florian van Dillen
@fvandillen
Sep 19 2016 19:53
I tested it before with a command
Works REALLY nice ingame
With a title and body for every notification
Tim Potze
@ikkentim
Sep 19 2016 19:54
Nice :) if ever you're ingame, take a screenie :P
If I push it's automatically compiled and unit tested on appveyor
If I tag the sampsharp repo, my pet @ikkentim-bot automatically creates a release, builds a nuget package, pushes it and adds the plugin as a zip to the github release
It also automatically versions every build
Still needs lots of work but that for another day, I'm out, laters